Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails f、 在Rails中选择不应用引导_Ruby On Rails_Forms_Twitter Bootstrap - Fatal编程技术网

Ruby on rails f、 在Rails中选择不应用引导

Ruby on rails f、 在Rails中选择不应用引导,ruby-on-rails,forms,twitter-bootstrap,Ruby On Rails,Forms,Twitter Bootstrap,我在Rails表单中有以下select元素: <%= f.select :customer_type, options_for_select(["Retail","Contractor","Dealer"]), class: "form-control" %> 有人知道为什么引导类“表单控件”没有呈现吗 我猜我的语法错了。感谢您的帮助 ,选择的方法签名为: select(object, method, choices, options = {}, html_options =

我在Rails表单中有以下select元素:

<%= f.select :customer_type, options_for_select(["Retail","Contractor","Dealer"]), class: "form-control" %>

有人知道为什么引导类“表单控件”没有呈现吗

我猜我的语法错了。感谢您的帮助

,选择的方法签名为:

select(object, method, choices, options = {}, html_options = {})
html\u选项
,这是您的html属性选项(如
:class
)应该放在
选项
之后,但是您忽略了
选项
,并将
html\u选项
放在
选项
之后。请尝试以下方法:

<%= f.select :customer_type, options_for_select(["Retail","Contractor","Dealer"]), {}, class: "form-control" %>


另外,如果您想知道为什么方法签名指定了
对象
,但在实际使用中,我们从未传递
对象
方法
总是第一位),这是因为我们实际上并没有直接调用此方法。当我们为块调用
f.select(…)
时,Rails为我们调用
select(f.object,…)

更新-如果您现在正在使用,您需要将类放入一个对象中:

<%= f.select :customer_type, options_for_select(["Retail","Contractor","Dealer"]), {}, { class: "form-control" } %>


我花了一些时间才弄明白,所以我觉得值得一贴:)

就是这样-谢谢你的回答和相关文档。你能解释一下选择和选择之间的区别吗?我真的无法从文档中看出这一点。
options
是一个令人困惑的名字,不幸的是。它不引用
HTML标记;它是指更改方法行为的选项。例如,我们可以传递
{include_blank:true}
使第一个
为空,或
selected:10
使默认值为
10
的选项处于选中状态。小问题是,您使用选项进行选择,然后在编辑页面上,它没有显示已从DB选择的项为什么?