简体   繁体   中英

f.select Not accepting values

I am using f.select here for these mark up values.

They appear in the drop down but when the form is submitted the value of 1.00 is displayed for any user's choice:

    <div class="field">
    <%= f.label :mark_up %><br>
    <%= f.select :mark_up, options_for_select([[1.00],[1.10],[1.15],[1.20],                    
    [1.25],[1.30],[1.35],[1.40],[1.45],[1.50]],:selected => params[:mark_up]) %> </div>

Try this:

<%= f.select(:mark_up, options_for_select([[1.00],[1.10],[1.15],[1.20],                    
[1.25],[1.30],[1.35],[1.40],[1.45],[1.50]], selected: :mark_up )) %>

See this link for more info on rails form helpers - options for select

Please the docs for options_for_select() for usage examples. You can use of both ways:

<%= f.select :mark_up, options_for_select([1.00, 1.10, 1.15, 1.20, 1.25, 1.30, 1.35, 1.40, 1.45, 1.50], :selected => f.object.mark_up)

or

<%= f.select :mark_up, options_for_select([1.00, 1.10, 1.15, 1.20, 1.25, 1.30, 1.35, 1.40, 1.45, 1.50], f.object.mark_up)

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