Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 为控制器加前缀,使其充满非资源路由rails_Ruby On Rails_Ruby On Rails 4_Routing_Rails Routing - Fatal编程技术网

Ruby on rails 为控制器加前缀,使其充满非资源路由rails

Ruby 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'

在rails
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