Module: ResourcefulController::CrudDefinitions
- Included in:
- ClassMethods
- Defined in:
- lib/resourceful_controller/crud_definitions.rb
Instance Method Summary collapse
- #default_methods ⇒ Object
- #define_create ⇒ Object
- #define_crud_methods ⇒ Object
- #define_destroy ⇒ Object
- #define_edit ⇒ Object
- #define_index ⇒ Object
- #define_new ⇒ Object
- #define_show ⇒ Object
- #define_update ⇒ Object
- #excepted_methods ⇒ Object
- #methods ⇒ Object
- #specified_methods ⇒ Object
Instance Method Details
#default_methods ⇒ Object
21 22 23 |
# File 'lib/resourceful_controller/crud_definitions.rb', line 21 def default_methods [:index, :new, :create, :show, :edit, :update, :destroy] end |
#define_create ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/resourceful_controller/crud_definitions.rb', line 37 def define_create define_method :create do instance_variable_set(:"@#{resource_name}", resource_class.new(params[:"#{resource_name}"])) if instance_variable_get(:"@#{resource_name}").save send(:redirect_to, show_path, :notice => "#{resource_name.titleize.capitalize} successfully created") else render :new end end end |
#define_crud_methods ⇒ Object
3 4 5 |
# File 'lib/resourceful_controller/crud_definitions.rb', line 3 def define_crud_methods methods.each { |method| send(:"define_#{method}") } end |
#define_destroy ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/resourceful_controller/crud_definitions.rb', line 71 def define_destroy define_method :destroy do resource = _find_query.call(params) resource.destroy redirect_to index_path, :notice => "#{resource_name.titleize.capitalize} successfully deleted" end end |
#define_edit ⇒ Object
54 55 56 57 58 |
# File 'lib/resourceful_controller/crud_definitions.rb', line 54 def define_edit define_method :edit do instance_variable_set(:"@#{resource_name}", _find_query.call(params)) end end |
#define_index ⇒ Object
25 26 27 28 29 |
# File 'lib/resourceful_controller/crud_definitions.rb', line 25 def define_index define_method :index do instance_variable_set(:"@#{resources_name}", _index_query.call(params)) end end |
#define_new ⇒ Object
31 32 33 34 35 |
# File 'lib/resourceful_controller/crud_definitions.rb', line 31 def define_new define_method :new do instance_variable_set(:"@#{resource_name}", resource_class.new) end end |
#define_show ⇒ Object
48 49 50 51 52 |
# File 'lib/resourceful_controller/crud_definitions.rb', line 48 def define_show define_method :show do instance_variable_set(:"@#{resource_name}", _find_query.call(params)) end end |
#define_update ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/resourceful_controller/crud_definitions.rb', line 60 def define_update define_method :update do instance_variable_set(:"@#{resource_name}", _find_query.call(params)) if instance_variable_get(:"@#{resource_name}").update_attributes(params[:"#{resource_name}"]) redirect_to show_path, :notice => "#{resource_name.titleize.capitalize} successfully updated" else render :edit end end end |
#excepted_methods ⇒ Object
13 14 15 |
# File 'lib/resourceful_controller/crud_definitions.rb', line 13 def excepted_methods Array.wrap(@options[:except]) end |
#methods ⇒ Object
7 8 9 10 11 |
# File 'lib/resourceful_controller/crud_definitions.rb', line 7 def methods methods = default_methods - excepted_methods methods = methods & specified_methods if specified_methods.present? return methods end |
#specified_methods ⇒ Object
17 18 19 |
# File 'lib/resourceful_controller/crud_definitions.rb', line 17 def specified_methods Array.wrap(@options[:only]) end |