Difference between form_for and form_tag?

前端 未结 3 777
野的像风
野的像风 2020-12-17 18:05

I used this gem in my application, but I\'m not sure the difference between the different implementation options for the gem:

  • form_for
  • form_tag with b
3条回答
  •  猫巷女王i
    2020-12-17 18:56

    As far as I know there is only one simple difference. form_tag without a block will only generate a html element for you. When you use form with a a block it will also create the form closing tag .

    In example:

    <% form_tag("/comments") %>
    

    will result in

    Where

    <%= form_tag("/comments") do %>
      <%= submit_tag %>
    <% end %>
    

    will generate

    
      
    
    

提交回复
热议问题