views:

129

answers:

1

I have an Employee model that has a SecurityClearanceLevel. When you make a new employee, you're asked to set a SecurityClearanceLevel by choosing from a <select> list. The problem is that when I save the object, it's a string, not a SecurityClearanceLevel, so the save fails.

Where do I take care of this kind of back-and-forth conversion, and what's the best way to do it?

+1  A: 

Rails gives you a few variations around doing this. You should be able to do something like this:

<%= collection_select(:employee, :security_clearance_level_id,
                      SecurityClearanceLevel.all, :id, :name) %>

Take a look at the Rails Guide on the select and option tags for the full details.

John Topley