Rodrigo Zurek
Rodrigo Zurek

Reputation: 4575

Routing non restfull controller

i have this controller:

gods_controller.rb

class GodsController < ApplicationController
  def notifications
    @reviews= Review.where("flag = ?", true)    
    respond_to do |format|
      format.html # index.html.erb      
    end
  end
end

routes.rb

resources :gods, :only => [:index] do
   get :notifications      
end

That route gives me this: http://example.com/gods/1/notifications

but what I want is this: http://example.com/gods/notifications

Thanks in advance!

Upvotes: 0

Views: 39

Answers (2)

Matheus Lima
Matheus Lima

Reputation: 2143

One thing you could do is, change your current route to this:

match "/gods/:id/notifications" => "gods#notifications"

Upvotes: 0

Rebitzele
Rebitzele

Reputation: 3282

Try:

resources :gods, :only => [:index] do
  collection do
    get :notifications      
  end
end

You can read more details about this here: http://guides.rubyonrails.org/routing.html#adding-more-restful-actions

Upvotes: 2

Related Questions