ruby on rails - options_from_collection_for_select wont allow selection by variable -


the 2 snippets of code below, options_from_collection_for_select works setting :selected when use set value, when use @posts.user_id fails.

why working?

select_tag "user-dropdown", options_from_collection_for_select(@users, 'id', 'fname', **11**), :class =>'form-control' 

but not?

select_tag "user-dropdown", options_from_collection_for_select(@users, 'id', 'fname', **@posts.user_id**), :class =>'form-control' 

select_tag "user-dropdown", options_from_collection_for_select(@users, 'id', 'fname', **@posts.user_id**), :class =>'form-control' 

what @posts.user_id trying display in options ?

select_tag options_for_select example

an example of using options_for_select select_tag

select_tag 'user_id', options_for_select(@users.collect{ |u| [u.name, u.id] }) 

this generate like:

<select id="user_id" name="user_id">   <option value="1">brad</option>   <option value="2">angie</option>   <option value="3">jenny</option> </select> 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -