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
Post a Comment