Flowdock

Notes posted by odradek

RSS feed
March 12, 2009
1 thank

Selected parameter

batasrki’s note on “selected” parameter is only true for cases which “value_method” returns an int also.

The strictly correct requirement for it to work is:

object.value_method == selected

(“object” is the current object on the iteration over collection)

Since the params hash returns Strings, using it against a value_method with return type of int will never give a valid match (thus no auto-selection is done), i.e., “13” != 13.

When you’ll be using other types of value_method, like String, there’s no need to append “.to_i”, e.g:

options_from_collection_for_select(@posts, "slug", "title", params[:slug])

where “slug” is a String, it will work as expected (current selected post is auto-selected by default).