I'm trying to make a restful route to Add and Remove relationships
between a Contact and a Customer.
I have a Contact and a Customer model that looks like
def Contact < ActiveRecord::Base
has_many :customer_mappings, :class_name =>
"ContactMapping", :foreign_key => "contact_id"
has_many :customers, :through => :customer_mappings
Customer model looks similar but with has_many :contacts.. instead.
In my contacts and customers controller I have methods to add and
remove a contact/customer, like this (very simplified):
ContactMapping.new(:customer => Customer.find(params[:customer_id])
Now, what is the best way to accomplish a named route for this in Rest-
I already have the map.resources :contacts in routes.rb.
What I'd like is an add_customer_contact_url (or similar) method so I
could do something like
form_remote_tag(:url => add_customer_contact_url(@contact), :method
=> :post) and then just pass along the customer_id.
I've tried various settings in routes.rb but I can't seem to get it
Can anyone help?