Module: Homeschool::ControllerExtensions::ClassMethods
- Defined in:
- lib/controller_extensions.rb
Overview
Add find_object, model_name
Instance Method Summary collapse
- #find_by_id(klass, options = {}) ⇒ Object
- #find_object(options = {}) ⇒ Object
- #model_class ⇒ Object
- #model_name ⇒ Object
Instance Method Details
#find_by_id(klass, options = {}) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/controller_extensions.rb', line 8 def find_by_id(klass, ={}) = {:name => klass.name.underscore, :param => :id}.merge() before_filter .filter(:only, :except) do |controller| controller.send(:instance_variable_set, [:name].to_sym.iv, klass.find(controller.params[[:param]])) end end |
#find_object(options = {}) ⇒ Object
4 5 6 |
# File 'lib/controller_extensions.rb', line 4 def find_object(={}) find_by_id(model_name, {:only => [:update, :edit, :show, :destroy]}.merge()) end |
#model_class ⇒ Object
19 20 21 |
# File 'lib/controller_extensions.rb', line 19 def model_class model_name.classify.constantize end |
#model_name ⇒ Object
15 16 17 |
# File 'lib/controller_extensions.rb', line 15 def model_name name.sub(/Controller$/, '').singularize.underscore end |