Hi guys,
I'm having the following many to many relationship in Rails (ActiveResource, of course):
class User < ...
has_many :channel_assignments
has_many :channels, :through => :channel_assignments
end
class Channel < ...
has_many :channel_assignments
has_many :users :through => :channel_assignments
end
class ChannelAssignment < ...
belongs_to :user
belongs_to :channel
end
Defined routes:
map.resources :users, :has_many => :channel_assignments
Update: rake routes gives the following output:
user_channel_assignments GET /users/:user_id/channel_assignments(.:format) {:action=>"index", :controller=>"channel_assignments"}
POST /users/:user_id/channel_assignments(.:format) {:action=>"create", :controller=>"channel_assignments"}
new_user_channel_assignment GET /users/:user_id/channel_assignments/new(.:format) {:action=>"new", :controller=>"channel_assignments"}
edit_user_channel_assignment GET /users/:user_id/channel_assignments/:id/edit(.:format) {:action=>"edit", :controller=>"channel_assignments"}
user_channel_assignment GET /users/:user_id/channel_assignments/:id(.:format) {:action=>"show", :controller=>"channel_assignments"}
PUT /users/:user_id/channel_assignments/:id(.:format) {:action=>"update", :controller=>"channel_assignments"}
DELETE /users/:user_id/channel_assignments/:id(.:format) {:action=>"destroy", :controller=>"channel_assignments"}
As ChannelAssignemnts are bound to user, I'm using my scaffolded ChannelAssignmentsController to automatically assign a user to a channel when creating a ChannelAssignment.
I'm doing that by using these URLs:
#/app/views/users/index.html.erb
#show a link to view all channels of a user
<%= link_to 'Channels', user_channel_assignments_path(user) %>
...
#/app/views/channel_assignments/new.html.erb
#assign a channel to currently selected user
<% form_for(@channel_assignment, :url => user_channel_assignments_path(@user) ) do |f| %>
...
That charmingly works.
But: Which is the path to unassign a channel, ergo: to delete a user's ChannelAssignment? Cannot find it when running rake routes.
Must be something like
<%= link_to 'Destroy', delete_user_channel_assignment, :user_id => @user, :method => :delete %>
Any input on this? I'm sure there is a way to autmatically have this URL generated.
Thanks
Matt