views:

117

answers:

3

I have some RESTful controllers and have added a custom method to application_controller. I have not changed anything in the routes to indicate this new method. The method is poll_memos. I have entered the following URL:

/groups/1234/poll_memos

I get the following error:

Unknown action

No action responded to 1234. Actions: create, destroy, edit, index, new, poll_memos, show, and update

Two questions: Since I didn't modify routes how does rails know about poll_memos? Second, since it seems to know about it, why is it not working?

+1  A: 

I don't think thats a restful route that rails automatically generates. This means you'll need to add it yourself.

Look at this question and this one.

And its in the actions because its in the controller, the error message is just printing all actions.

MrHus
+1  A: 

The correct url is /groups/poll_memos/1234. In your example rails thinks that you're trying to call controller method named "1234", which is absent, of course.

Rails knows about poll_memos because the code that prints the error message looks at controller code, not to the routing. You may set routes up in such a way that it will say that there is poll_memos method, but you're unable to access it via URL.

Pavel Shved
+1  A: 

This is because you are most likely triggering the default route:

map.connect ':controller/:action/:id'

Your URL

/groups/1234/poll_memos

would map as follows:

{:controller => "groups", :action => "1234", :id => "poll_memos"}

Also, as you are using a restful style you need to configure the route. To get the poll memos working on the items in the collection you'll need to modify your routes to map as follows:

map.resources :groups, :member => {:poll_memos => :get}
dmcnally