how does rails know if it should submit a form to update or create?

108 views
Skip to first unread message

fugee ohu

unread,
Dec 25, 2015, 2:16:37 AM12/25/15
to Ruby on Rails: Talk
how does rails know if it should submit a form to update or create? the form is rendered by either new or edit so on submission how does rails know which action originally rendered the form?

nanaya

unread,
Dec 25, 2015, 3:17:53 AM12/25/15
to rubyonra...@googlegroups.com
by checking the value returned by `object.persisted?`.

Colin Law

unread,
Dec 25, 2015, 4:14:36 AM12/25/15
to Ruby on Rails: Talk
Have a look at the html for the edit and new pages and I think you
will see a difference. Look at the form tag in particular.

Colin

fugee ohu

unread,
Dec 26, 2015, 5:34:57 PM12/26/15
to Ruby on Rails: Talk
they're the same, <%= render 'form' %> is all they contain other than links and either  <h1>New model</h1> or <h1>Editing model</h1>

Colin Law

unread,
Dec 27, 2015, 2:57:02 AM12/27/15
to Ruby on Rails: Talk


On 26 Dec 2015 22:35, "fugee ohu" <fuge...@gmail.com> wrote:
>
> they're the same, <%= render 'form' %> is all they contain other than links and either  <h1>New model</h1> or <h1>Editing model</h1>

I said to look at the HTML not your source code.  The form tag is the HTML generated by the form_for code.

Also please don't top post, as I have asked before. Thanks.

Colin

>
> On Friday, December 25, 2015 at 4:14:36 AM UTC-5, Colin Law wrote:
>>
>> On 25 December 2015 at 07:16, fugee ohu <fuge...@gmail.com> wrote:
>> > how does rails know if it should submit a form to update or create? the form
>> > is rendered by either new or edit so on submission how does rails know which
>> > action originally rendered the form?
>>
>> Have a look at the html for the edit and new pages and I think you
>> will see a difference.  Look at the form tag in particular.
>>
>> Colin
>

> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/791ad873-6fde-465e-9d91-c945d4c911d4%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages