Ruby on rails 如何获取用于处理模块的url_?

Ruby on rails 如何获取用于处理模块的url_?,ruby-on-rails,Ruby On Rails,我已在我的routes中安装了FullcalendarEngine.rb: mount FullcalendarEngine::Engine , at: "/fullcalendar_engine" resources :events, module: 'fullcalendar_engine' 不幸的是,即使我在routes.rb中有这样的内容: mount FullcalendarEngine::Engine , at: "/fullcalendar_engine" resource

我已在我的routes中安装了FullcalendarEngine.rb:

mount FullcalendarEngine::Engine , at: "/fullcalendar_engine"
resources :events,  module: 'fullcalendar_engine'
不幸的是,即使我在routes.rb中有这样的内容:

mount FullcalendarEngine::Engine , at: "/fullcalendar_engine"
resources :events,  module: 'fullcalendar_engine'
以及生成的路由:

fullcalendar_engine_path                    /fullcalendar_engine        FullcalendarEngine::Engine
events_path                     GET         /events/index(.:format)     fullcalendar_engine/events#index
event_path                      GET         /events/:id(.:format)       fullcalendar_engine/events#show
events_path                     GET         /events(.:format)           fullcalendar_engine/events#index
                                POST        /events(.:format)           fullcalendar_engine/events#create
new_event_path                  GET         /events/new(.:format)       fullcalendar_engine/events#new
edit_event_path                 GET         /events/:id/edit(.:format)  fullcalendar_engine/events#edit
event_path                      GET         /events/:id(.:format)       fullcalendar_engine/events#show
                                PATCH       /events/:id(.:format)       fullcalendar_engine/events#update
                                PUT         /events/:id(.:format)       fullcalendar_engine/events#update
                                DELETE      /events/:id(.:format)       fullcalendar_engine/events#destroy
我仍然无法将
url\u用于
(我需要这样做才能使它与
will\u paginate
)一起工作:

错误:

({controller:'events',action:'index'})的RailsDevise::Application.routes.url_ =>ActionController::UrlGenerationError:没有路由匹配{:action=>“index”,:controller=>“events”} ({controller:'events',action:'index'})的FullcalendarEngine::Engine.routes.url_ =>ActionController::UrlGenerationError:没有路由匹配{:action=>“index”,:controller=>“events”}

当我检查模块的路径时:

FullcalendarEngine::Engine.routes.routes.collect {|journey| journey.defaults }
 => [{:controller=>"fullcalendar_engine/events", :action=>"index"}, {:action=>"get_events", :controller=>"fullcalendar_engine/events"}, {:action=>"move", :controller=>"fullcalendar_engine/events"}, {:action=>"resize", :controller=>"fullcalendar_engine/events"}, {:action=>"index", :controller=>"fullcalendar_engine/events"}, {:action=>"create", :controller=>"fullcalendar_engine/events"}, {:action=>"new", :controller=>"fullcalendar_engine/events"}, {:action=>"edit", :controller=>"fullcalendar_engine/events"}, {:action=>"show", :controller=>"fullcalendar_engine/events"}, {:action=>"update", :controller=>"fullcalendar_engine/events"}, {:action=>"update", :controller=>"fullcalendar_engine/events"}, {:action=>"destroy", :controller=>"fullcalendar_engine/events"}] 
请注意,它具有以下特性:

@defaults={:controller=>"fullcalendar_engine/events", :action=>"index"}
请注意控制器值的名称空间。这不起作用:

FullcalendarEngine::Engine.routes.url_for({:controller=>"events", :action=>"index"})
ActionController::UrlGenerationError: No route matches {:action=>"index", :controller=>"events"}
但如果我尝试为其命名,则会出现以下错误:

FullcalendarEngine::Engine.routes.url_for({:controller=>"fullcalendar_engine/events", :action=>"index"})
ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
即使添加主机也会生成错误的url:

FullcalendarEngine::Engine.routes.url_for({:controller=>"fullcalendar_engine/events", :action=>"index", host: "localhost"})
 => "http://localhost/fullcalendar_engine/" 

如何获取
url\u以识别路由?

您的路由需要
id
参数,因此您需要为其指定一个:

url_for(controller: 'events', action: 'show', id: 5)   # < Notice the `id`
url_for(controller:'events',action:'show',id:5)#<注意'id'`

此外,您发布的路由不包括
索引的路由,因此它可能不存在。如果是这样的话,其他遇到这种情况的人可能不需要
id

。我逐步阅读了Rails代码,这是我修复它的原因:

FullcalendarEngine::Engine.routes.url_for({:action=>"index", host: "localhost"}, 'fullcalendar_engine_path')

事实上,我最初并没有发布所有的路线。确实有一条索引路线。我更新了问题。