Shamoon
Shamoon

Reputation: 43531

Adding additional routes to Rails 3

I have a comments controller:

  match 'comments/count' => 'comments#count'
  resources :comments

I'm trying to map mysite.com/comments/count to a newly defined count action within the comment controller. What I have above doesn't seem to work. I get the following error:

Unknown action

The action 'show' could not be found for CommentsController

Upvotes: 0

Views: 78

Answers (1)

phoet
phoet

Reputation: 18845

even though i think that this should work, there are better ways to do this. have a look at the member and collection attributes of resources:

resources :photos do
  member do
    get 'preview'
  end
end

http://guides.rubyonrails.org/routing.html#adding-more-restful-actions

in your case i think this would be

resources :comments do
  get 'count', :on => :collection
end

Upvotes: 3

Related Questions