views:

650

answers:

1

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?

+2  A: 

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.

inkdeep