路由非宁静的控制器

时间:2013-04-03 19:10:40

标签: ruby-on-rails ruby ruby-on-rails-3

我有这个控制器:

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

这条路线给了我这个:http://example.com/gods/1/notifications

但我想要的是:http://example.com/gods/notifications

提前致谢!

2 个答案:

答案 0 :(得分:2)

尝试:

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

您可以在此处详细了解详情:http://guides.rubyonrails.org/routing.html#adding-more-restful-actions

答案 1 :(得分:0)

您可以做的一件事是,将您当前的路线更改为:

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