I was trying to redirect to a different page after editing an entry, I assumed that it was using the update code because you are updating the database. It took me some time to realise that I was using the wrong action in the controller. Can someone please explain how edit and update work. Why are there two different actions? what are the differences between them?
-
I have tasks that can be broken up into two different categories. I have created a controller for each category that links to the same model for tasks. when i submit the edit form it is redirecting back to the main tasks controllers show action. It seems to be skipping the com_tasks controller all together (com_tasks = one of the category controllers). I looked at the html output that is rendered and the form is being submitted to the wrong controller, but I can't see any way to change that. – Rumpleteaser Oct 12 '10 at 00:46
2 Answers
edit action is responsible for rendering the view
update action is responsible for interacting with the model (db updates etc)
If you run rake routes
you will see the difference between the verb and the action. Typically, the create/update actions are used when submitting a form. This differs from the new and edit actions as these are used to render the view (that displays the form to be submitted).

- 11,050
- 12
- 44
- 58
-
in what order are they called? what process does it go through? edit -> update -> edit? If i put a redirect in edit it won't get to the update? – Rumpleteaser Oct 12 '10 at 00:28
-
Correct. If you want to redirect someone *after* they have updated an entry, you put the redirect in the update action. – theIV Oct 12 '10 at 00:55
-
1So just 2 events in that chain: edit, which renders the form, then update, when the user submits it. If you redirect_to to go the a different page (default is often the show view in a scaffold), then you'd have a third one. – Joost Schuur Oct 12 '10 at 03:15
-
Another perspective - a bit redundant to highlight similarities and differences:
New is the precursor action to render a form, that upon submitting, runs the Create action. (the view is typically redirected back to the index view showing a list of similar items you already created)
Edit is the precursor action to render a form, that upon submitting, runs the Update action. (the view is typically redirected back to the index view showing a list of similar items you already created)

- 296
- 3
- 14