Skip to content

Commit

Permalink
controller DRY updates
Browse files Browse the repository at this point in the history
  • Loading branch information
braidn committed Aug 11, 2013
1 parent 4877690 commit 3864f4d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
16 changes: 11 additions & 5 deletions RailsActionController.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
Instructions on how your app will handle certain requests(called methods or 'actions'). Some things to think about:
##Notes

>Instructions on how your app will handle certain requests(called methods or 'actions'). Some things to think about:
* Unless otherwise declared, all methods in a controller class are public.
* Usually when actions complete their work they respond by rendering a view by using a RespondToBlock
* The controller responds to the user exactly once per request.
* This means that you could not have two `render()` methods per request
* ex: `respond_to do |format| end`
* This means that you could not have two `render()` methods per request
* use the keyword `return` to jump early out of a resource
* [RestfulControllers][1]
* [RailsFilters][2]
* If in the controller and you pass `respond_to` an item not surrounded by {} then it looks for it's name (create, delete, show) in the proper view directory.
* If you place a `private` method in the application controller it will be accessible by ALL controllers BUT never as an action

### Other Resources

* [RestfulControllers][1]
* [RailsFilters][2]
* [RenderOptions][3]
* [RenderToOptions][4]
* [RailsControllerScrathPad][5]
Expand All @@ -17,4 +23,4 @@ Instructions on how your app will handle certain requests(called methods or 'act
[2]: /RailsFilters
[3]: /RenderOptions
[4]: /RenderToOptions
[5]: /RailsControllerScrathPad
[5]: /RailsControllerScrathPad
4 changes: 4 additions & 0 deletions RailsSessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
* This leads to most cookies containing the "cart_id" for example over everything actually in the cart
* ALL volatile data should be kept in the database

###Best Practices

* Storing info in sessions/on the client side are good for 2/3 step flows

[1]: /RailsFlash
[2]: /RailsResourceVsResources
1 change: 1 addition & 0 deletions RailsUrlHelpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ modules contain a number of methods that let you reference resources external to
* could also be written as `link_to 'Name', {:controller => 'articles', :action => 'new'}, {:class => 'awesome_sauce'}`
* these will always default to the HTTP GET request
* although the `:method` modifier can change this to whatever
* using `link_to :back` hooks into some jQuery gold and pushes you back one page
* `button_to` acts identical to `link_to` but, defaults to POST

###Nesting
Expand Down
13 changes: 9 additions & 4 deletions RestfulControllers.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
You have seven default actions, and in every one of them you do the following:
##Notes

* Set an instance variable to be used later in the rendered action or template
* Handle the response using the respond_to method to either do a render or redirect_to another path, depending on the behavior you want to achieve
* When rendering a partial or temp from another controller use: `<%= render :file => 'controllerName/tempName' %>`
* You have seven default actions, and in every one of them you do the following:
* Set an instance variable to be used later in the rendered action or template
* Handle the response using the respond_to method to either do a render or redirect_to another path, depending on the behavior you want to achieve
* When rendering a partial or temp from another controller use: `<%= render :file => 'controllerName/tempName' %>`
* `new` and `edit` are _actually_ not RESTFUL
* these end up being different ways to represent the `show` action
* this can be thought of while building an API, why build new over create
* the big five(`index`, `show`, `create`, `update`, `destroy`) are what matter

0 comments on commit 3864f4d

Please sign in to comment.