【发布时间】:2009-06-30 18:46:12
【问题描述】:
过去三天我一直在为我的“列表”选择表单助手 - 表单,用户可以在其中选择一个类别。
我希望将当前在 listing.category_id 中设置的类别作为预选值。
我的视图代码如下所示:
<%= l.collection_select(:category_id, @category, :id, :name, options = {},
html_options = {:size => 10, :selected => @listing.category_id.to_s})%>
我知道这是不正确的,但即使阅读 Shiningthrough (http://shiningthrough.co.uk/blog/show/6) 的解释,我也无法理解如何继续。
感谢您的支持,
迈克尔
查看:
如上
控制器:
def categories #Step 2
@listing = Listing.find(params[:listing_id])
@seller = Seller.find(@listing.seller_id)
@category = Category.find(:all)
@listing.complete = "step1"
respond_to do |format|
if @listing.update_attributes(params[:listing])
flash[:notice] = 'Step one succesful. Item saved.'
format.html #categories.html.erb
end
end
end
【问题讨论】:
-
我在原来的答案中添加了一个可能的解决方案。
标签: ruby-on-rails ruby