Wednesday, July 04, 2007

How to use select_tag to create drop down menus in Rails

select_tag :size, options_for_select(["Small", "Medium", "Large"])

This will create a drop down with the values in the array. You can either declare a constant array in the model and use that like: MyModel::SHIRT_SIZES instead of hard coding it. If it is database driven, write a helper that will return an array of options.

No comments:

Post a Comment