Ruby on Rails select_tag default value

When using the Rails helper select_tag, the selected value (ie highlighted value) is a parameter to options_for_select, not select_tag. Eg:

Number of Rows: <%= select_tag(:numrows, options_for_select(%w{10 20 50 100 200 500}, session[:numrows])) %>

(much head-banging-against-wall went into working this out…)



Share This


 


7 Responses to Ruby on Rails select_tag default value

  1. Spam alert above! Thanks for this lil tidbit. Good to know.

  2. Thanks Mark. Spam zapped – somehow it slipped thru…

  3. Thanks, this helped me out!

  4. Good tips.This really helped me. I have come across this problem twice. This is the second time i face the same problem. Why, there is not standard for the selection in rails.

  5. Thanks for this snippet… Really helped me a lot… @ the right time too.. :)

  6. thanks for this.. highly appreciated! :)

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>