我有这个控制器:
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
提前致谢!
答案 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"