Categories
ruby on rails

Rails collection_select helper

The explanation from api.rubyonrails.org is rather baffling for a newbie like me,

collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})

Still managed to get the dropdown menu working for my application after searching through the web. There are already quite a few useful resources available in the net for helper method collection_select.

But I seem to lost in the code again looking back at it after a while. And am too lazy to look through all the stuff again. So I try to make a diagram to put down what I already understand from those resources. Might not be the best or complete explanation, but just try to help myself to be able to view it and quickly get a grasp of it.
collection_select_explain_3

By kahfei

A system admin by day while secretly trying to transform myself to a coding designer or a designing coder at night.

12 replies on “Rails collection_select helper”

Have to say this is not the most comprehensive collection_select post out there BUT it is straight to the point and illustrates the theory perfectly. Good job

You just saved my life. The ‘method” thing was killing me. Read this and it works.
Thank you. Ben

eeeeee, sorry for the problem, I am changing my blog layout, and seeing some images are exceeding the blog width, so I shrunk them. I will try to fix it over the weekend.

Great post about collection_select. You just saved some hours of my life. Thanks a lot 🙂
P.S. The image is little, though it’s readable enough

Hi Alex,

Glad that it is useful to you.
I plan to redrawn the image so it is more visible, as soon as I find the time to do it.

the image is fine, it just needs to be displayed normally. and not to complain, but hardset 400px content columns are user-hostile and lame.

eh, yes, definitely, am working on a new layout, ha, but the progress is really slow at the moment. 😉

I am using the multi select, but i have a edit form and when i try get the values that were stored in the db it doesn’t render as selected, any advice?

Leave a Reply

Your email address will not be published. Required fields are marked *