Rails routing: resources with only custom actions

rails-routing, restful-architecture, ruby-on-rails, ruby-on-rails-3

Solution

If you are using scope, you should add a controller looks like

scope :notifications, :controller => 'notifications' do
  post 'clear'
end

Or just use namespace

namespace :notifications do
  post 'clear'
end

Problem

I have a `NotificationsController`, in which I only have the action `clear`. I'd like to access this action by doing POST /notifications/clear So I wrote this in my router: ``` resources :notifications, :only => [] do collection do post :clear end end ``` Is there a cleaner way to achieve this? I thought ``` scope :notifications do post :clear end ``` would do it, but I have a `missing controller` error, because - I think - it looks for the `clear` controller.

Original source

Related problems