depassion
asked on
radio buttons to display list of options - rails app
so i have this collection select to select a category of job:
instead i want to show the categories as a list of radio buttons a user can select rather than a drop down list.
<%= collection_select(:job, :category_id, Category.all, :id, :name, {:include_blank => '-select job type-'} ) %>
instead i want to show the categories as a list of radio buttons a user can select rather than a drop down list.
ASKER
i did actually mean radio button as in the category section here https://jobs.37signals.com/jobs/new, as only 1 category can be selected
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
If you take a look at the has_many method in the Rails API, a has_many association sets up Job#category_ids and Job#category_ids= for the job instance:
Open in new window
So in your view you could do:Open in new window
With check boxes, though, if no check box has been checked no data for that form name would be sent to the server. In your controller action, you would have to ensure the value passed for categories_id is an array:Open in new window