Leave a specific option selected when using a select

Asked

Viewed 47 times

-1

I am generating a select passing some options as shown in the code below

select name="listing_search[realty_types][]"
  - Realty.translated_realty_types.each do |k, v|
    option value="#{v}" #{k} 

How do I leave the second option selected from the list selected? I know SELECTED exists, but I’m not sure how to use it.

1 answer

1

  - Realty.translated_realty_types.each_with_index do |k, v, index|
    - if index == 0
      option selected value="#{v}" #{k} 
    - else
      option value="#{v}" #{k} 
  • Thanks, I changed some things and it was!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.