我在routes.rb中安裝FullcalendarEngine:如何獲取url_for使用模塊?
mount FullcalendarEngine::Engine , at: "/fullcalendar_engine"
不幸的是,即使我有這個在routes.rb中:
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_for
(爲了使它與will_paginate
一起工作,我需要這麼做):
錯誤:
RailsDevise::Application.routes.url_for({ controller: 'events', action: 'index'}) => ActionController::UrlGenerationError: No route matches {:action=>"index", :controller=>"events"} FullcalendarEngine::Engine.routes.url_for({ controller: 'events', action: 'index'}) => ActionController::UrlGenerationError: No route matches {: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_for
來識別路線?
其實我最初並沒有發佈所有的路線。確實有一個索引路線。我更新了這個問題。 – Donato