Adding values to a select box from a controller function (Ruby on Rails)?

Take a look at options_for_select It builds the html for what you want to display.

Take a look at options_for_select. It builds the html for what you want to display. Options_for_select("Dollar", "$", "Kroner", "DKK") Dollar\nKroner options_for_select( "VISA", "MasterCard" , "MasterCard") VISA\nMasterCard options_for_select({ "Basic" => "$20", "Plus" => "$40" }, "$40") Basic\nPlus options_for_select( "VISA", "MasterCard", "Discover" , "VISA", "Discover") VISA\nMasterCard\nDiscover You can just pass the result of this function to select_tag like so.

Thanks! How would you return the result of the options_for_select function from the function which will be calling it in the controller in order to insert it into the select box? – Corey Dec 19 '09 at 20:35 Edit my answer to show how to invoke.

– Jeff Paquette Dec 19 '09 at 22:52.

Doing things like populating a select are best done in a helper. If your controller is named MyController then you can have a MyHelper module in the helpers directory. Methods, etc.Inside the helper will be available inside your view templates.

So, you could have a populate_select method in your MyHelper and do everything there that you are wanting to do in your controller. That's more "the Rails way." Helpers are intended to handle the heavy Ruby code that your templates need so you don't have to mix it with your XHTML.

– Corey Dec 19 '09 at 23:56 Yes, it would be the same. The point is that you want to separate your view/presentation logic from you application/business logic. The former belongs in a helper, the latter belongs in the controller.

Think of helpers as an extension of the "V" in MVC. Since select boxes and other inputs only appear in views, they should be prepared by a view helper. – Chris Dec 20 '09 at 16:25.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions