我需要将以下成员方法添加到一些资源中,有没有办法把它干掉?
member do
get :votes
post :up_vote
post :down_vote
end
在我的 routes.rb
resources :news do
resources :comments do
member do
get :votes
post :up_vote
post :down_vote
end
end
end
resources :downloads do
resources :whatever do
member do
get :votes
post :up_vote
post :down_vote
end
end
end
编辑
我实际上已经把它移到了一个模块中,如下所示:
module Votable
module RoutingMethods
def votable_resources
member do
get "up_votes"
get "down_votes"
post "up_vote"
post "down_vote"
end
end
end # RoutingMethods
end
现在,我的 routes.rb 看起来像这样:
require 'votable'
include Votable::RoutingMethods
MyApp::Application.routes.draw do
namespace :main, :path => "/" do
resources :users do
resources :comments do
votable_resources
end
end
end
end
请参阅我的内联注释,但我希望命名路由看起来像:main_users_comments_up_votes