include bootstrap role attribute in rails form helper

大兔子大兔子 提交于 2019-12-21 01:14:06

问题


Twitter Bootstrap has this role attribute for forms:

<form role="form">

How can I include the role attribute in Rails form helpers? I tried this, but it doesn't work:

<%= form_for @user, class: "form-horizontal", role: "form" do |f| %>

回答1:


You need to specify it as an html option:

<%= form_for @user, html: {class: "form-horizontal", role: "form"} do |f| %>



回答2:


form_for and form_tag have to be used differently:

form_for:

<%= form_for @user, html: { class: "form-horizontal", role: "form" } do |f| %>

form_tag:

<%= form_tag some_path, class: "form-horizontal", role: "form" do |f| %>


来源:https://stackoverflow.com/questions/19622056/include-bootstrap-role-attribute-in-rails-form-helper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!