开发者

Rails — Formtastic, how to set text for options in select?

开发者 https://www.devze.com 2023-01-01 20:01 出处:网络
f.input :some_model_values, :as => :select Using Formtastic, I need to set a text for options on my select input, but not populated from :some_model_开发者_运维知识库values.
f.input :some_model_values, :as => :select

Using Formtastic, I need to set a text for options on my select input, but not populated from :some_model_开发者_运维知识库values.

The second: how could be collection of :some_model_values pre-modefied? Because i don want to show some options according to user role.

Thanks!


What do You mean with "set a text for option on my select input" ?

Please have a look at the :collection parameter, for example:

f.input :some_model_values, :as => :select, :collection => [1,2,3,4]

or

f.input :some_model_values, :as => :select, :collection => [["male",1], ["female",2], ["other",3]]

When you want to set the label, the best option is to localise it by the /config/locales/#locale#.rb file

Hope this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消