Module: ResponderController::Actions
- Defined in:
- lib/responder_controller/actions.rb
Overview
The seven standard restful actions.
Instance Method Summary collapse
-
#create ⇒ Object
Build, save, assign and respond with a new model.
-
#destroy ⇒ Object
Find and destroy a model.
-
#edit ⇒ Object
Find, assign and respond with a single model.
-
#index ⇒ Object
Find, assign and respond with models.to_a.
-
#new ⇒ Object
Build (but do not save), assign and respond with a new model.
-
#show ⇒ Object
Find, assign and respond with a single model.
-
#update ⇒ Object
Find, update, assign and respond with a single model.
Instance Method Details
#create ⇒ Object
Build, save, assign and respond with a new model.
The model is created with attributes from the request params, under the InstanceMethods#model_slug
key.
36 37 38 39 40 |
# File 'lib/responder_controller/actions.rb', line 36 def create self.model = find_models.build(params[model_slug]) model.save respond_with_contextual model end |
#destroy ⇒ Object
Find and destroy a model. Respond with InstanceMethods#models_slug
.
54 55 56 57 |
# File 'lib/responder_controller/actions.rb', line 54 def destroy find_model.destroy respond_with_contextual models_slug end |
#edit ⇒ Object
Find, assign and respond with a single model.
27 28 29 30 |
# File 'lib/responder_controller/actions.rb', line 27 def edit self.model = find_model respond_with_contextual model end |
#index ⇒ Object
Find, assign and respond with models.to_a.
5 6 7 8 |
# File 'lib/responder_controller/actions.rb', line 5 def index self.models = find_models respond_with_contextual models.to_a end |
#new ⇒ Object
Build (but do not save), assign and respond with a new model.
The new model is built from the InstanceMethods#find_models
collection, meaning it could inherit any properties implied by those scopes.
21 22 23 24 |
# File 'lib/responder_controller/actions.rb', line 21 def new self.model = find_models.build respond_with_contextual model end |
#show ⇒ Object
Find, assign and respond with a single model.
11 12 13 14 |
# File 'lib/responder_controller/actions.rb', line 11 def show self.model = find_model respond_with_contextual model end |
#update ⇒ Object
Find, update, assign and respond with a single model.
The new attributes are taken from the request params, under the InstanceMethods#model_slug
key.
46 47 48 49 50 |
# File 'lib/responder_controller/actions.rb', line 46 def update self.model = find_model model.update_attributes(params[model_slug]) respond_with_contextual model end |