Module: Resourceful::Default::Actions
- Defined in:
- lib/resourceful/default/actions.rb
Overview
Contains the definitions of the default resourceful actions. These are made available with the Builder#actions method.
These methods are very compact, so the best way to understand them is just to look at their source. Check out Resourceful::Accessors and Resourceful::Callbacks for the documentation of the methods called within the actions.
Along with each action is listed the RESTful method which corresponds to the action. The controller in the examples is FoosController, and the id for single-object actions is 12.
Instance Method Summary (collapse)
-
- (Object) create
POST /foos.
-
- (Object) destroy
DELETE /foos/12.
-
- (Object) edit
GET /foos/12/edit.
-
- (Object) index
GET /foos.
-
- (Object) new
GET /foos/new.
-
- (Object) show
GET /foos/12.
-
- (Object) update
PUT /foos/12.
Instance Method Details
- (Object) create
POST /foos
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/resourceful/default/actions.rb', line 34 def create build_object load_object before :create if current_object.save save_succeeded! after :create response_for :create else save_failed! after :create_fails response_for :create_fails end end |
- (Object) destroy
DELETE /foos/12
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/resourceful/default/actions.rb', line 88 def destroy #load_object before :destroy if current_object.destroy after :destroy response_for :destroy else after :destroy_fails response_for :destroy_fails end end |
- (Object) edit
GET /foos/12/edit
81 82 83 84 85 |
# File 'lib/resourceful/default/actions.rb', line 81 def edit #load_object before :edit response_for :edit end |
- (Object) index
GET /foos
17 18 19 20 21 |
# File 'lib/resourceful/default/actions.rb', line 17 def index #load_objects before :index response_for :index end |
- (Object) new
GET /foos/new
73 74 75 76 77 78 |
# File 'lib/resourceful/default/actions.rb', line 73 def new build_object load_object before :new response_for :new end |
- (Object) show
GET /foos/12
24 25 26 27 28 29 30 31 |
# File 'lib/resourceful/default/actions.rb', line 24 def show # NOTE - Moved this call to a more generic place #load_object before :show response_for :show rescue response_for :show_fails end |
- (Object) update
PUT /foos/12
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/resourceful/default/actions.rb', line 50 def update #load_object before :update begin result = current_object.update_attributes object_parameters rescue ActiveRecord::StaleObjectError current_object.reload result = false end if result save_succeeded! after :update response_for :update else save_failed! after :update_fails response_for :update_fails end end |