Rails 3.1 可安装引擎:如何在另一个应用程序中使用/模板化它? [英] Rails 3.1 Mountable Engines : How to use/template it inside another application?

查看:32
本文介绍了Rails 3.1 可安装引擎:如何在另一个应用程序中使用/模板化它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我创建了一个名为Soho"的可安装引擎,它有一个用于用户"的控制器.我可以去/users/1 查看我的 ID 为 1 的用户.

Let's say I created a mountable engine called 'Soho' that has a controller for 'Users'. I can go to /users/1 to see my user with ID 1.

在Soho"内部,我有一个用于布局的 application.html.erb.

Inside 'Soho', I have a application.html.erb for layout.

现在假设我想在名为Soho_test"的应用程序中混合"我的引擎Soho",并将我的引擎安装在/".因此,在我的主机应用程序Soho_test"中,我还可以访问/users/1 查看 ID 为 1 的用户.这是有效的.

Now let's assume I want to "blend" my engine 'Soho' in an application called 'Soho_test', and I mount my engine at "/". So, in my host application 'Soho_test', I can also go at /users/1 to see my user with ID 1. This is working.

我的问题是:如何在我的主机应用程序Soho_test"中将Soho_test"application.html.erb 应用到/users/1(用户配置文件页面)而不是Soho"可安装页面引擎?

My question is : how can I do in my host application 'Soho_test' to apply the 'Soho_test' application.html.erb to the /users/1 (user profile page) instead of the one in the 'Soho' mountable engine?

谢谢!

推荐答案

我找到了如何实现它,所以我会在我自己的问题上发布我的答案,以防其他人想知道.这实际上很容易.我一开始就应该考虑这个...

I found how to achieve it, so I will post my answer on my own question, in case anyone else wonders. It is actually quite easy. I should have thought about this in the first place...

您所要做的就是在您的 /views/layouts/ 中创建一个包含您引擎名称的文件夹.所以根据我的问题,它将是 /views/layouts/soho/.在该文件夹中,放入您想要的 application.html.erb.

All you have to do is to create a folder in your /views/layouts/ with the name of your engine. So according to my question, it would be /views/layouts/soho/. In that folder, put the application.html.erb that you want to have.

您可以对局部视图和其他视图执行相同操作.只需创建一个文件夹 /views/soho/.../ 并将您的文件放在那里.我还没有找到在我的主机应用程序中复制引擎视图的 rake 任务,所以我写了一个.

You can do the same with partials and other views. Just create a folder /views/soho/.../ and put your files there. I havn't found a rake task to copy the engine views in my host application, so I wrote one.

这篇关于Rails 3.1 可安装引擎:如何在另一个应用程序中使用/模板化它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆