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?

+2


source to share


3 answers


I don't think this is a calm route that automatically creates rails. This means you have to add it yourself.

Have a look at question and.



And in actions, because in the controller, the error message just prints all actions.

+1


source


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.

+1


source


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}

      

+1


source







All Articles