Rails is selected by the helper. How to choose a default value?

In Rails erb, I use a snippet to show the invited team in a tournament match. How do I show the current visit_team first? What am I doing wrong?

<%= f.select(:visiting_team_id, Team.all.collect{|t| [t.name, t.id] }) %>
+3
source share
2 answers

The fix is ​​to explicitly indicate the selected option. Now it looks like it likes and works

<%= f.select(:visiting_team_id, Team.all.collect{|t| [t.name, t.id]}, {:selected => @match.visiting_team_id.to_i}) %>
+2
source

Just make sure the object you pass in form_forhas the correct set visiting_team_id. Then, while there is a command that is pulled with this identifier, it should work

0
source

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


All Articles