2012-07-20 88 views
7

這裏我想呈現引擎的父應用程序的佈局,即在層次結構引擎的父應用程序中.html.erb應該更高。但由於引擎也得到了application.html.erb,它只渲染它,而不渲染引擎的父級application.html.erb。Rails引擎:呈現父應用程序佈局

我怎樣才能使我的父母application.html.erb與我的引擎application.html.erb沿

感謝

回答

10

在您的發動機控制器可以使用:

layout 'application' 

爲了渲染應用程序佈局,或者您可以切換到:

layout 'engine_name/application' 

加載engi ne的佈局。

我不知道你是否可以加載它們(引擎佈局應該只能從應用程序佈局繼承並擴展它),但我希望它至少能讓你更進一步。

+2

我明白了,但還有一個疑問,在我的application.html.erb中,我使用了<%= link_to「Sign out」,destroy_user_session_path,:method =>:delete%>,如果路徑從引擎延伸,它會顯示eror「未定義的局部變量或方法'destroy_user_session_path」 如何解決它 – 2012-07-20 21:05:35

+1

@ParitoshSingh你可以通過引用'engine來解決這個問題。 destroy_user_session_path'而不僅僅是'destroy_user_session_path',其中'engine'是引擎的名稱。 – 2014-01-28 04:36:58

相關問題