简体   繁体   English

Rails simple_form标签用于选择

[英]Rails simple_form label for select

I'm trying to set a label for the following line but I keep getting an error if I add label_method anywhere. 我正在尝试为下一行设置标签,但是如果我在任何地方添加label_method,都会出现错误。 label: is just ignored. 标签:只是被忽略。 How can I add a label for f.select? 如何为f.select添加标签?

<%= f.select :state_identifier, Location::STATE, { prompt: 'State', id: 'state' } %>

I tried the following but it doesn't format properly in form-horizontal, leaving no gap between the label and data. 我尝试了以下操作,但是它在水平格式下无法正确格式化,因此标签和数据之间没有间隙。

<%= f.label :state_identifier, label: 'State' %>

This is because f.select is not a simple_form method and does not support :label 这是因为f.select不是simple_form方法,并且不支持:label

Something like this should work for you w/ simple form. 像这样的东西应该适合您w /简单的形式。

<%= f.input :state_identifier, :label => "State", :collection => ["a","b"], :input_html => {:id=>"state" } %>

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM