form_for and form_tag, when to use which one?

后端 未结 2 1491
失恋的感觉
失恋的感觉 2020-12-28 19:07

I am reading a Rails book and so far it has been using form_for to create the forms. In the new chapter that it is building a login page for users, it is using

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-28 19:41

    form_tag simply creates a form. form_for creates a form for a model object. They are not interchangeable and you should use the one that is appropriate for a given case.

    form_for is a bit easier to use for creating forms for a model object because it figures out what url to use and what http method to use depending on whether the object is a new record or a saved record.

提交回复
热议问题