Hi! Thanks for visiting my blog. If you've received any value from my content would you mind supporting my new startup by downloading our browser add-on? It's called PriceBlink and makes online shopping a breeze. You can watch it in action here and download it for Chrome, Firefox, IE, or Safari by going to PriceBlink.com. Thank you and I hope you enjoy!

Dynamic Select Lists in Rails

Nov 14

I’ve come to find out that Rails has pretty good support for dynamic select lists.  This is achieved through different form helpers, one of which is called collection_select.  You can read more about collection_select here.  The usage is simple and the best part of this is that you get pre-select functionality for free.  To clarify, let’s say you’re adding a product to your web store and associating it with a category called “books”.  The next time you go to edit the product the “books” category will be pre-selected in the drop down menu.  This can be achieved through the following code:

collection_select(:product, :category_id, @categories, :id, :name) 

Instead of duplicating content I will let you read more about the parameters by going here. Once again Rails, thank you for making my life simpler and letting me focus on solving more important problems.

Leave a Reply