开发者

Problem with form_for Helper

I have the following form_for declaration in a Rails site I am building:

form_for(form_question, :url => { :controller => "form_questions", :action => "edit", :id => form_questio开发者_开发百科n.id }) do |f|

but the site renders;

<form action="/form_questions/1/edit">

why is it putting the '/1/' before the "edit" in the action url?


Simple Answer. RESTful routes.

Basically you have defined resources :form_questions in config/routes.rb and that is transforming, automagically, your URL to make it RESTful.


I would recommend using the RESTful helpers provided to you, like:

<% form_for(@form_question) do %>
  <%= f.text_field :question %>
  ...
<% end %>

Which will generate a URL to either create or update depending on if the @form_question response to new_record? is true or false respectively. It'll also do other things, like give the form tag a different id attribute based also off what new_record? returns.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜