Show selected option in dropdown on edit in Rails Simple Form

1.4k views Asked by At

I am trying to make an app with rails 4 and simple form.

When I want to edit a saved project, I am taken back to my form which asks displays the original questions, but without the inputs selected on creation.

Is there a way to set the form so that if you click edit, the previous selections are shown? It looks like I haven't made choices of inputs in the manner in which the edit form is displayed.

For example, one of my questions is:

<%= par.select :location,
   options_for_select(["London", "Paris", "Berlin"]),
   label: 'Where will participants take part in this project?',
   prompt: "Choose one",
   class: 'response-project' %>

When I check London on create, it saves that choice. When I then press edit, the form displays 'choose one'. It looks like I haven't saved London (which I have - the db shows that choice).

1

There are 1 answers

4
potashin On BEST ANSWER

You can try the following to set current location as selected option instead of the prompt option:

options_for_select(["London", "Paris", "Berlin"], selected: :location)