2012-07-20 53 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

相关问题