only one select box shows up due to duplicate id

I have a form where there can be three select boxes depending upon a checkbox - I'm using jQuery to show/hide them depending on which checkbox is active. Below, `f` is `player` <% Game.all.each_with_index do |game, i| %>
<%= f.collection_select(:team_division_id, TeamDivision.where("game_id = ?", game.id), :id, :name, include_blank: true) %>
<% end %> Each collection select is generating an id of `player_team_division_id` - and since there can be only one id a page, this is really screwing with my results, namely the first select box shows up fine, but the others show up as simple links to `javascript:void(0)` - if I check out the generated divs with firebug/chrome, the information is there, it just isn't showing up as a select box (presumably) because of the id. I'm using chosen.js, if that makes a difference, although I'm don't think this has any affect. **Edit (Models)**: class Player < ActiveRecord::Base belongs_to :game belongs_to :team_division, touch: true end class Game < ActiveRecord::Base has_many :players has_many :team_divisions end Class TeamDivision < ActiveRecord::Base has_many :players belongs_to :game end
I think you can change :id in collection_select parameters to some variable that will be unique for the view. Eg, combination of game.id and team_division_id. And you really shouldn't have stuff like TeamDivision.where in your view. I'm sure there will be much better solution to your problme. Can you post your models (Game, Player, Team and TeamDivision) relationships? I'm think, in this case, it would be better to go without collection_select, but I cannot be sure until I know relationships...

以上就是only one select box shows up due to duplicate id的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » HTML5 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏