开发者

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 %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜