Ruby on rails 为控制器加前缀,使其充满非资源路由rails
在railsRuby on rails 为控制器加前缀,使其充满非资源路由rails,ruby-on-rails,ruby-on-rails-4,routing,rails-routing,Ruby On Rails,Ruby On Rails 4,Routing,Rails Routing,在rails4.2中,我有一个控制器,我想用非资源路由填充它,比如 class TwilioController < ApplicationController def add_to_queue end def another_action end end 但是,有没有一种方法可以将所有这些问题组合在一起,这样我就不必在每条路线的开头明确地添加twilio。好的,我已经找到了一个解决方案,它看起来相当简洁 scope path: 'twilio', as: 't'
4.2
中,我有一个控制器,我想用非资源路由填充它,比如
class TwilioController < ApplicationController
def add_to_queue
end
def another_action
end
end
但是,有没有一种方法可以将所有这些问题组合在一起,这样我就不必在每条路线的开头明确地添加
twilio
。好的,我已经找到了一个解决方案,它看起来相当简洁
scope path: 'twilio', as: 't' do
get 'add-to-queue', to: 'twilio#add_to_queue'
end
所以我现在有这样的路线:
t_add_to_queue GET /twilio/add-to-queue(.:format) twilio#add_to_queue
这是我在Rails 3.2中使用的解决方案
scope :path => :twilio, :controller => :twilio, :as => :twilio do
get :add_to_queue
get :another_action
get :yet_another_action
end
:路径将\twillio\…
添加到URL
:控制器
将所有嵌套路由映射到控制器
:as
在URL帮助程序的后面附加twillio_uz...
scope :path => :twilio, :controller => :twilio, :as => :twilio do
get :add_to_queue
get :another_action
get :yet_another_action
end