Skip to content

Instantly share code, notes, and snippets.

View adamkleingit's full-sized avatar

Adam Klein adamkleingit

View GitHub Profile
@adamkleingit
adamkleingit / method_only_in_parent.rb
Last active December 18, 2015 15:59
Define secret methods only in parent
module SecretMethods
def secret_def(name, &block)
klass = self
define_method name do
if self.class != klass
raise NoMethodError
else
yield
end
end
@adamkleingit
adamkleingit / sti_routes.rb
Created June 17, 2013 20:52
Routes for STI models
# If you want url_for(CoolProject) to give you 'cool_projects/1' but still go to ProjectsController then:
resources :cool_projects, :controller => :projects
# If you want url_for(CoolProject) to give you 'projects/1' and also go to ProjectsController then:
resources :cool_projects, :controller => :projects, :as => :projects
# If you want to reuse stuff inside resources:
projects_inner = lambda do
member do
resources :submodels