views:

32

answers:

2

Hi I am a newbie, please forgive me if I am asking silly question. After I created the controller, views and Model using scafolding for article

I see same code in both new and edit views.

<% form_for(@article) do |f| %>
  <%= f.error_messages %>
    ..................
  <p>
    <%= f.submit "Updaggggte" %>
  </p>
<% end %>

when I check the source for these pages New has

<form action="/articles" class="new_article" id="new_article" method="post"><div style="margin:0;padding:0"><input name="authenticity_token" type="hidden" value="757ad93da031eb40a64360318f05e2cc9ada1fc6" /></div>

Edit has

<form action="/articles/1" class="edit_article" id="edit_article_1" method="post"><div style="margin:0;padding:0"><input name="_method" type="hidden" value="put" /><input name="authenticity_token" type="hidden" value="757ad93da031eb40a64360318f05e2cc9ada1fc6" /></div>

How is _method hidden field included in Edit page??

Thanks in advance

A: 

This field is provided by the form_for helper method. In case of a new record, @aritcle.new_record? will be true, and since you set your application up using scaffolding, the Article model is mapped as a resource (have a look at config/routes.rb), so the helper method will know exactly what method it has to use to create a new article record.

cite
A: 

Hi Thanks for your response. With your answer and this link

http://apidock.com/rails/ActionView/Helpers/FormHelper/form_for

I am now able to understand how the URL is generated and how I could modify the default behavior.