views:

38

answers:

0

I have models moves, neighborhoods and communities.

Neighborhood.rb
  has_many :communities
  has_many :moves, :through => :communities
  accepts_nested_attributes_for :communities

Move.rb
   has_many :communities
   has_many :neighborhoods, :through => :communities
   accepts_nested_attributes_for :communities

Community.rb
   belongs_to :move
   belongs_to :neighborhood

In my application your move can have several neighborhoods that belong to that move. In addition a neighborhood can belong to more than one person's move. So I have the join model Community.

On the neighborhood show view I want to have a button that says "Save this neighborhood to my move."

In an effort to accomplish this I am using this form:

<% form_for([@move, @neighborhood]) do |f| %>
@move.id %> @neighborhood.id %>

<% end %>

I have no idea if this is the best way to do this. The PROBLEM is that whenever I add a neighborhood to a different move it updates the Communities table with that move_id for every id with that neighborhood_id. I am not sure how I just add a new community (id, move_id, neighborhood_id) without updating anything else.

Maybe this is the complete wrong way of doing this. I could really use some help or suggestions.

Thanks