← Back to Upcase

Sticking to the 7 resourceful actions in a controller


(Jameson Trinker) #1

In Part Two he says to stick to the seven resourceful actions when writing controllers, but then he adds in other methods. He uses the sessions_controller as an example, which has two additional methods: set_flash_message and session_params. I’m just curious what he means by sticking to the 7. And how do I know when its alright to add a method to a controller?

Thanks!


(Jaroslav Janukevic) #2

The 7 golden restful actions

  • Index
  • Show
  • Destroy
  • New
  • Create
  • Edit
  • Update

You should try to stick to them, because it will be easier to understand the code for others and yourself. It will make it easier to implement an API and you stick with the HTTP methods(the links below explains better)

So instead of writing display_this_tweet you should write show
When neither of the 7 actions fit your purpose make your own.

For more read http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions and https://en.wikipedia.org/wiki/Representational_state_transfer


(David Briggs) #3

In addition to what @janukevic has said, the seven resourceful actions are public methods.

In the case of the sessions controller, the 2 methods that were added were private. These methods are used only inside the context of the sessions controller and not accessed from outside it like the seven resourceful actions.


(Jameson Trinker) #4

Thank you for your help!