maverick
maverick

Reputation: 800

Rails select, keep value?

this is probably embarrassing to ask and pretty simple. What I wanna do is, when I'm editing my profile, I want my selector to keep its value which I choose at the first time. For example:

Status: Single, In a relationship, Engaged, Married.

If I choose In a relationship and I want to edit that, the value is still there and not in the order "Single, In a relationship and so on..." Here's my code:

<%= c.select(:relationship_status, options_for_select([["Singel", :singel], ["I ett förhållande", :förhållande], ["Förlovad", :förlovad], ["Gift", :gift]], {:prompt => true, :selected => !!params[:relationship_status]})) %>  

Upvotes: 2

Views: 1642

Answers (1)

mind.blank
mind.blank

Reputation: 4880

Try this:

c.select(:relationship_status, options_for_select([["Singel", :singel], ["I ett förhållande", :förhållande], ["Förlovad", :förlovad], ["Gift", :gift]], params[:relationship_status]), prompt: true)

If you look at the documentation for options_for_select it has the following example:

options_for_select([ "VISA", "MasterCard" ], "MasterCard")

<option>VISA</option>
<option selected="selected">MasterCard</option>

Upvotes: 2

Related Questions