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?
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Design RESTful service with multiple ids
- Axios OPTIONS instead of POST Request. Express Res
- Plain (non-HTML) error pages in REST api
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
- Rspec controller error expecting <“index”> but
- Factory_girl has_one relation with validates_prese
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).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)