Rails 关于 options_for_select 的问题,求解

yingjie_xiao · August 23, 2013 · Last by yingjie_xiao replied at August 23, 2013 · 1984 hits

options_for_select([ categories.each do |category| [category.id, category.name] end ],value) categories 是一个对象数组,我上面这种形式只能获取到第一个对象,其他的获取不到,它的正确用法是这样的吧: options_for_select([[l(:label_all_time), 'all'], [l(:label_today), 'today'], [l(:label_yesterday), 'yesterday'], [l(:label_this_week), 'current_week'], [l(:label_last_week), 'last_week']], value) 但是[category.id, category.name]后面加,号的话,程序会报错

我想问的就是怎么动态的给 options_for_select 添加 option

options_for_select(categories.map{|category| [category.id, category.name]}, value)
You need to Sign in before reply, if you don't have an account, please Sign up first.