views:

16

answers:

2

I have the following routes in my app:

                       GET    /admin/comments(.:format)                 {:controller=>"admin/comments", :action=>"index"}
        admin_comments POST   /admin/comments(.:format)                 {:controller=>"admin/comments", :action=>"create"}
     new_admin_comment GET    /admin/comments/new(.:format)             {:controller=>"admin/comments", :action=>"new"}
                       GET    /admin/comments/:id(.:format)             {:controller=>"admin/comments", :action=>"show"}
                       PUT    /admin/comments/:id(.:format)             {:controller=>"admin/comments", :action=>"update"}
         admin_comment DELETE /admin/comments/:id(.:format)             {:controller=>"admin/comments", :action=>"destroy"}
    edit_admin_comment GET    /admin/comments/:id/edit(.:format)        {:controller=>"admin/comments", :action=>"edit"}
 admin_approve_comment        /admin/comments/approve/:id               {:module=>"admin", :controller=>"admin/comments", :action=>"approve"}
  admin_reject_comment        /admin/comments/reject/:id                {:module=>"admin", :controller=>"admin/comments", :action=>"reject"}

which is declared as:

  namespace "admin" do

    resources :comments

    match '/comments/approve/:id' => 'comments#approve', :as => "approve_comment", :module => "admin"
    match '/comments/reject/:id' => 'comments#reject', :as => "reject_comment", :module => "admin"
  end

and a functional test like this:

context "a POST to :approve" do
    setup do
      comment = Factory(:comment)
      sign_in Factory(:admin)
      post :approve, :id => comment.id 
    end

    should respond_with :success
end

However, when I run this I get:

test: a POST to :approve should respond with 200. (Admin::CommentsControllerTest):
ActionController::RoutingError: No route matches {:action=>"approve", :id=>339, :controller=>"admin/comments"}

What's wrong here? What stupid mistake am I making?

A: 

I think it's better to put match before resources. Because it's not check if it's good or not.

shingara
+1  A: 

These routes look like member routes to me. So routing this way

  namespace "admin" do
    resources :comments do
      member do
        get :approve
        get :reject
      end
    end
  end

This will generate routes like /admin/comments/:id/approve . This is the rails way as far i know.

Rishav Rastogi