i would like to know how to add a ‘selected option’ for selec box?
I assume you are looking to have the select box automatically select
the recipe category if it already exists? If that’s the case, you need
to change your helper to the following:
The select helper method will call the category_id method on your @recipes object and automatically add the selected=“selected”
attribute for the correct option.
As an aside, you might also be interested in my acts_as_dropdown
plugin for helping to make these select boxes cleaner. You can find
out more about it here: http://delynnberry.com/pages/acts_as_dropdown,
but it basically allows you to do this:
class Category < ActiveRecord::Base
acts_as_dropdown :text => “nom”
end
As an aside, you might also be interested in my acts_as_dropdown
plugin for helping to make these select boxes cleaner. You can find
out more about it here: http://delynnberry.com/pages/acts_as_dropdown,
but it basically allows you to do this:
class Category < ActiveRecord::Base
acts_as_dropdown :text => “nom”
end