Skip to content

Instantly share code, notes, and snippets.

View railsbob's full-sized avatar

Anup Narkhede railsbob

View GitHub Profile
gem 'saas', :require => 'saas', :path => 'lib/saas'
# Saas/controllers/saas/sessions_controller.rb
module Saas
class SessionsController < ApplicationController
def new
render :text => 'Hi from SessionsController'
end
end
end
# Saas/config/engine.rb
module Saas
class Engine < Rails::Engine
engine_name :saas
end
end
# Saas/lib/saas.rb
module Saas
require File.expand_path('../../config/engine', __FILE__)
end
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'saas'
s.version = '0.1'
s.description = 'A generic modular application.'
s.required_ruby_version = '>= 1.8.7'
s.author = 'Anup Narkhede'
s.require_path = 'lib'
end
# MyApp/lib/saas/config/routes.rb
Rails::Application.routes.draw do |map|
namespace :saas do
resources :sessions
end
end
# Pretty commified numbers
module ApplicationHelper
def format_num(num, delim = ',')
number_with_precision(num, :precision => 2, :separator => '.', :delimiter => ',')
end
end
# To fix unicode character errors in mysql
# => Put this file in lib and require it in environment.rb
require 'mysql'
class Mysql::Result
def encode(value, encoding = "utf-8")
String === value ? value.force_encoding(encoding) : value
end
# Which folder is eating up the space?
du -s * | sort -n
# We want the account namespace routes available only if subdomains are specified
constraints(:subdomain => /[A-Za-z0-9]/) do
namespace :account do
resources :users
end
end