我尝试使用select_tag选择默认选项。这是我的收藏
@model_names = {
'Fixed' => 'fixed',
'Variable' => 'variable',
'LIBOR' => 'libor'
}
这是select_tag
select_tag "second_model", options_for_select(@model_names, 'LIBOR')
我试过了两个' LIBOR'并且' libor'。甚至{' LIBOR' => ' libor'}作为options_for_select
的第二个参数。但它不起作用。当集合是哈希时,如何设置默认选项?
//修改
哦,它适用于' libor'和...禁用JavaScript。我使用selectBoxIt插件,它没有使用它。任何人都知道如何使用Rails + selectBoxIt jQuery插件选择默认值?
答案 0 :(得分:0)
如果您尝试将变量设置为数组而不是散列,则设置默认选项可能会更好。然后你可以做一些像options_for_select([['默认','默认'] [@ model_names]])。在您的drop中,它将默认为默认值,并在下拉列表中显示您的集合。你可以乱用它,这里有几个帮助链接。
RoR select_tag default value & options
http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_for_select