Forum: Ruby on Rails Custom Actions with REST

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
B75f9bc2b05e37ab421f17d7845645c5?d=identicon&s=25 David Scheffel (david-x)
on 2007-02-06 21:41
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?

15c80c9bf8be5ba6e5eeac9cb0304464?d=identicon&s=25 Ed Hickey (Guest)
on 2007-02-06 22:06
(Received via mailing list)
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.

B75f9bc2b05e37ab421f17d7845645c5?d=identicon&s=25 David Scheffel (david-x)
on 2007-02-07 10:19
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

This topic is locked and can not be replied to.