Custom Actions with REST

Hi there.

I’d like to add a custom action, let’s call it “add_association”, that
will add a relation between two models that are linked using
has_and_belongs_to_many. I’ve tried the following, …

member.resources :model_b, :member => { :associate => :post }

… which creates a route like
http://localhost:3000/model_a/9/model_b/associate which seems to be ok.
But when I try to request that url, I receive the following error:

Unknown action
No action responded to show

That’s weird. How could that custom action be linked with show?


With that route, you need to POST to this URI:

I assume you tried calling
http://localhost:3000/model_a/9/model_b/associatewith the GET method
so Rails is looking for the “model_b” with a id of
“associate” since GET maps to Controller#show.


Thanks! That makes sense.

But how to write an action that could be used to search for an entry in
model_b and would then call “associate” with post to link the two models

Would I need to write a separate controller for the porpose of