0

我有这个控制器:

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

路线.rb

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

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

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

提前致谢!

4

2 回答 2

2

尝试:

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

您可以在此处阅读有关此内容的更多详细信息:http: //guides.rubyonrails.org/routing.html#adding-more-restful-actions

于 2013-04-03T19:30:34.487 回答
0

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

match "/gods/:id/notifications" => "gods#notifications"
于 2013-04-03T19:32:32.350 回答