How to use form_for helper in rails?
New to rails. I am using form_for helper in rails 2.3.5. The question is, when edit开发者_JAVA技巧ing a record, I cannot use:
<% form_for :myrecord, :url => {:action => :update} %>
...
<% end %>
But I have to use:
<% form_for @myrecord, :url => {:action => :update} %>
... # the same as above
<% end %>
When I use the first code, it always return error saying undefined method. Shouldn't the first code and the second code serves the same when "myrecord" is the name of the instance passed from controller to view?
Thank you for any hints and answers.
form_for take a block so it's more like. If this record is same that resource, the :url option is not needed. FormHelper check if @myrecord is #new_record? or not. If new_record use POST instead use PUT.
<% form_for @myrecord do |f| %>
<%= f.text_field :field %>
<% end %>
精彩评论