Rail routing problem
I have some RESTful controllers and added a custom method to application_controller
. I haven't changed anything in the routes to indicate this new method. Method poll_memos
. I entered the following url:
/ groups / 1234 / poll_memos
I am getting the following error:
Unknown action
No action responds to 1234. Actions: create, destroy, edit, index, new, poll_memos, show and update
Two questions: Since I haven't changed the routes, how do rails know about poll_memos
? Secondly, since he seems to know about it, why isn't it working?
source to share
The correct url is / groups / poll_memos / 1234. In your example, rails thinks you are trying to call a controller method named "1234" which is of course missing.
Rails is aware of poll_memos because the code that prints the error is looking at the controller code, not the routing. You can set up routes so that it says there is a poll_memos method, but you cannot access it via a URL.
source to share
This is because you are most likely running the default route:
map.connect ':controller/:action/:id'
Your url
/groups/1234/poll_memos
will display like this:
{:controller => "groups", :action => "1234", :id => "poll_memos"}
Also, since you are using a calm style, you need to adjust the route. To get the poll tabs working on items in the collection, you need to change the routes to display as follows:
map.resources :groups, :member => {:poll_memos => :get}
source to share