Ruby on Rails : symbol as argument in form_for

后端 未结 1 1427
忘掉有多难
忘掉有多难 2020-11-30 12:08

I understand what is passed to the form_for method when doing something like :

<% form_for(@user) do |f| %> ... <% end %>

相关标签:
1条回答
  • 2020-11-30 12:37

    Using the symbol will generate:

    <form action="/users" method="post">
    

    Using the object @user set to new you get:

    <form action="/users/create" class="new_user" id="new_user" method="post">
    

    If you set @user to something else it will change the form tag generated, of course ... try it out for yourself.

    In the end it all depends what you're trying to do. You might want to use the symbol if you have multiple :user forms on the same page.

    0 讨论(0)
提交回复
热议问题