Skip to content

Instantly share code, notes, and snippets.

@nordringrayhide
Created October 3, 2010 06:01
Show Gist options
  • Save nordringrayhide/608312 to your computer and use it in GitHub Desktop.
Save nordringrayhide/608312 to your computer and use it in GitHub Desktop.
module InheritedResources
module DefaultActions
def self.included(base)
base.send :extend, ClassMethods
end
module ClassMethods
def default_actions(*actions_to_keep)
options = actions_to_keep.extract_options!
actions_to_keep.map!(&:to_sym).uniq!
actions_to_keep = ACTIONS if actions_to_keep.first == :all
actions_map = { :update => :edit, :create => :new }
actions_to_keep.each do |action|
if actions_map.has_key?(action)
method = "#{action}! {|success, failure| failure.html {render 'resource/#{actions_map[action]}'}} "
else
method = "#{action}! {|format| format.html {render 'resource/#{action}'}}"
end
class_eval "def #{action}; #{method};end"
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment