开发者

Rails select helper. How do I select the default value?

In Rails erb, am using the snippet to show visiting team in a tournament match. How do I get to initially show the current visit开发者_如何学运维ing_team? What am I doing wrong?

<%= f.select(:visiting_team_id, Team.all.collect{|t| [t.name, t.id] }) %>


The fix is to explicitly specify the selected option. It now looks likes this and works

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


Just ensure that the object you're passing to form_for has the correct visiting_team_id set. Then, so long as there's a team that gets pulled out with that ID, it should work

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜