我有一個Rails 3應用程序與幾個引擎包含附加功能。每個引擎都是一項獨立的服務,客戶可以購買訪問權限。如何從主機應用程序提供Rails 3引擎的路由?
但是,我有一個問題,來自引擎的路由,這些引擎對於控制器和視圖來說並不容易獲得。
控制器:
class ClassroomsController < ApplicationController
..
respond_to :html
def index
respond_with(@classrooms = @company.classrooms.all)
end
def new
respond_with(@classroom = @company.classrooms.build)
end
..
end
app/views/classrooms/new.html.haml
:
= form_for @classroom do |f|
..
f.submit
在發動機config/routes.rb
:
MyEngineName::Engine.routes.draw do
resources :classrooms
end
config/routes.rb
在應用程式:
Seabed::Application.routes.draw do
mount MyEngineName::Engine => '/engine'
...
end
發動機lib/my_engine_name.rb
:
module MyEngineName
class Engine < ::Rails::Engine
end
end
試圖去/classrooms/new
結果
NoMethodError in Classrooms#new
Showing app/views/classrooms/_form.html.haml where line #1 raised:
undefined method `hash_for_classrooms_path' for #<Module:0x00000104cff0f8>
,並試圖調用classrooms_path
從同樣的錯誤任何其他查看結果。 但是,我可以撥打MyEngineName::Engine.routes.url_helpers.classrooms_path
並使其正常工作。我想我可能已經定義了錯誤的路線,但找不到另一種方法。
嘗試使用Passenger(獨立和Apache模塊)和WEBrick(rails服務器)運行應用程序。使用Git的最新Rails(7c920631ec3b314cfaa3a60d265de40cba3e8135
)。
做的是,除在我的應用程序的路由安裝呼叫和範圍界定在發動機路線(`scope'/ engine'do`),一切正常。非常感謝:) – PerfectlyNormal 2010-12-06 00:57:06
很酷,感謝獲取引擎路線工作所需的其他步驟信息。 – bowsersenior 2010-12-06 03:27:24