Reputation: 1573
I am trying to accomplish Create and Edit on the same view (and same controller) on Rails 3.2 and Ruby 1.9.2. I have a partial and I am using form_for
and the standard form helpers.
I submit using Ajax, so my page (form) is not refreshed or redirected. When the user tries to edit the form, naturally, Rails will create an entry instead of updating it. I was thinking of modifying the Controller's create
method to detect existing entries, but I am not sure if this is the correct approach. Thanks.
Upvotes: 0
Views: 866
Reputation: 3365
You can pretty easily include the same form in both create and edit pages by storing it in a partial (typically _form.html.erb
) and rendering the form in both create and edit.
This is what rails generate scaffold MODEL FIELD:TYPE FIELD1:TYPE1
will give you, as well.
Upvotes: 1