我花了最近三天的时间来处理我的"列表" - 表单的集合_选择表单助手,用户可以在其中选择一个类别.
我想将listing.category_id中当前设置的类别作为预选值.
我的视图代码如下所示:
<%= l.collection_select(:category_id, @category, :id, :name, options = {},
html_options = {:size => 10, :selected => @listing.category_id.to_s})%>
Run Code Online (Sandbox Code Playgroud)
我知道这是不正确的,但即使阅读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
Run Code Online (Sandbox Code Playgroud)