RoR differences between :url, :action, :method in form_for

后端 未结 3 1428
广开言路
广开言路 2020-12-13 07:24

There might be answers in documentation, but i don\'t seem to find good answers. So among the three :url, :action, :method, what are their differences when used in form_for

3条回答
  •  心在旅途
    2020-12-13 07:36

    form_for is basically used on object. For example:

          <% form_for @person do |f| %>
           ...
          <% end %>
    

    When you click submit it will go to default action like from :new to :create, :edit => :update. If you want to specify your own action then you have to use :url and :method is used to force to post or get. For example:

          <% form_for @person :url => {:action => "my_action"}, :method => "post" do |f| %>
           ...
          <% end %>
    

提交回复
热议问题