简体   繁体   中英

Rails: Default Value - select field

I want to display a default select value. What I have so far is:

<%= f.collection_select(:user_id, User.where(brand: current_user.brand), :id, :name, {prompt:true}, {class: 'form-control'}, :selected => current_user.brand) %>

But this produces an error:

wrong number of arguments (7 for 4..6)

Any ideas what the problem is?

This should do the trick:

<%= f.collection_select(:user_id, User.where(brand: current_user.brand), :id, :name, {prompt: true}, {class: 'form-control', selected: current_user.brand}) %>

selected should be in the html_options . See also: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM