Hello,
I spent the last three days working on the collection _ select form helper for my "listing" - form, where users can select a category.
I would like to have the category currently set in listing.category_id as the preselected value.
My view code looks like this:
<%= l.collection_select(:category_id, @category, :id, :name, options = {},
html_options = {:size => 10, :selected => @listing.category_id.to_s})%>
I know this is not correct, but even reading looking at the explanation from Shiningthrough (http://shiningthrough.co.uk/blog/show/6) I can not understand how to proceed.
Thank you for your support,
Michael
View:
as above
Controller:
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