在 Rails 中使用嵌套 insert_html 部分时出错
所以我有两个嵌套的部分,并调用 insert_html。 基本上每个团队都有多个玩家,我有一个添加玩家按钮和一个添加团队按钮,每个按钮都使用以下助手调用部分内容
module TeamsHelper
def add_team_link(name)
link_to_function name do |page|
page.insert_html :bottom, :teams, :partial => 'team', :object => Team.new
end
end
def add_player_link(name2)
link_to_function name2 do |page2|
page2.insert_html :bottom, :players, :partial => 'player', :object => Player.new
end
end
end
如果我只使用一个 insert_html 调用,那么效果很好,但当我尝试同时使用这两个按钮时,我会收到 javascript 错误“参数列表后缺少)”和外部“添加团队”按钮失败。 有任何想法吗?
So I have two nested partials with calls to insert_html. Basically each team has multiple players and I have an add player button and an add team button which each call a partial with the following helpers
module TeamsHelper
def add_team_link(name)
link_to_function name do |page|
page.insert_html :bottom, :teams, :partial => 'team', :object => Team.new
end
end
def add_player_link(name2)
link_to_function name2 do |page2|
page2.insert_html :bottom, :players, :partial => 'player', :object => Player.new
end
end
end
This works just fine if I only use one insert_html call but when I try to have both I get a javascript error "missing ) after argument list" and the outer "add team" button fails. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 add_player_link 的 link_to_function 放入您为团队渲染的部分中。 然后,您可以分配要插入项目的团队 Div 的唯一 ID:
<%= link_to_function name2 执行 |page2|
page2.insert_html :bottom, "players_#{unique_id}", :partial => '玩家', :object => Player.new
每个团队 DOM 元素是否都有唯一的 ID? 我遇到了问题,我有两个 id="order" 的 div 并且它破坏了东西。 就像你有很多“团队”div,里面有很多“玩家”div。 尝试为每个人提供一个唯一的 ID,当您有两个团队时,第二个按钮可能会开始工作。
You can put the add_player_link's link_to_function into the partial you're rendering for the teams. Then you can assign the unique ID of the Team Div you want to insert items into:
<%= link_to_function name2 do |page2|
page2.insert_html :bottom, "players_#{unique_id}", :partial => 'player', :object => Player.new
Does each team DOM element have a unique ID? I've had problems where I'll have two divs with id="order" and it breaks stuff. It liks like you'd have many "team" divs with many "player" divs inside them. Try giving each one a unique ID and the second button when you have two teams will probably start working.