Rails 4 - Retaining Form values on refresh -



Rails 4 - Retaining Form values on refresh -

i'm working on rails 4 ecommerce app. on order page, when collecting address info, have state dropdown using helper method lists states.

<%= f.select(:state, options_for_select(us_states), {prompt: "select"}, {class: "form-control"}) %>

when user has error in form - credit card number entered wrong, when page refreshes error message, state dropdown autoselcts "alabama" since first state listed in dropdown.

is there alternative can utilize retain selected state?

note: other info address, etc retained. state dropdown not retained.

you can retain previous state as:

<%= f.select(:state, options_for_select(us_states, f.object.state_id), {prompt: "select"}, {class: "form-control"}) %>

i assume have association defined model , so, foreign key state_id.

ruby-on-rails

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -