Select_tag rails question

I have select_tag, like this: Select something something 1 something 2 ...

After I selected something 2 and clicked the submit button, it will refresh the page, but on select_tag it will display β€œSelect something else”. How can I make him show something 2?

+4
source share
1 answer

It depends on how you display the select tag, but if you use options_for_select, you can do this:

  @selected = params [: selected]

 select_tag: selected, options_for_select ([[[Something 1 ", 1], [" Something 2 ", 2]], @selected)

It will indicate options for selection that @selected will use as the selected value.

+6
source

Source: https://habr.com/ru/post/1336845/


All Articles