在 Rails 4 如何以 DRY 方式向表单添加字段?
In Rails 4 how do I add fields to a form in a DRY manner?
在我的 Rails 4 项目中,我想在服务器端的控制器的所有表单中添加 2 个字段。
我想将此添加到我的控制器的所有表单中。
input name="authenticity_token" type="hidden" value='=form_authenticity_token'
input name="profilePage" type="hidden" value='#{params[:action]}'
每个视图都有一种形式。
您可以将其设为部分:
#_csrf.html.slim
input name="authenticity_token" type="hidden"value='=form_authenticity_token'
input name="profilePage" type="hidden" value='#{params[:action]}'
然后以各种形式渲染它:
= render 'csrf'
在我的 Rails 4 项目中,我想在服务器端的控制器的所有表单中添加 2 个字段。
我想将此添加到我的控制器的所有表单中。
input name="authenticity_token" type="hidden" value='=form_authenticity_token'
input name="profilePage" type="hidden" value='#{params[:action]}'
每个视图都有一种形式。
您可以将其设为部分:
#_csrf.html.slim
input name="authenticity_token" type="hidden"value='=form_authenticity_token'
input name="profilePage" type="hidden" value='#{params[:action]}'
然后以各种形式渲染它:
= render 'csrf'