Module: ResourceController::ClassMethods

Defined in:
lib/resource_controller/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#actions(*opts) ⇒ Object

Use this method in your controller to specify which actions you’d like it to respond to.

class PostsController < ResourceController::Base
  actions :all, :except => :create
end


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/resource_controller/class_methods.rb', line 9

def actions(*opts)
  config = {}
  config.merge!(opts.pop) if opts.last.is_a?(Hash)

  all_actions = (singleton? ? ResourceController::SINGLETON_ACTIONS : ResourceController::ACTIONS) - [:new_action] + [:new]
  
  actions_to_remove = []
  actions_to_remove += all_actions - opts unless opts.first == :all                
  actions_to_remove += [*config[:except]] if config[:except]
  actions_to_remove.uniq!

  actions_to_remove.each { |action| undef_method(action) if method_defined?(action) }
end