简体   繁体   English

Rails 3.1 - 从可安装引擎访问父应用程序模型

[英]Rails 3.1 - Accessing Parent Application Models from Mountable Engine

I want to create a parent application that deals with the User Authentication. 我想创建一个处理用户身份验证的父应用程序。 I then want to create various Mountable Engines (like a blog, contact directory, etc.) that can be added as needed. 然后,我想创建可以根据需要添加的各种可安装引擎(如博客,联系人目录等)。 This means that I will need to access the User Authentication data (admin rights, etc.) from the Mountable Engine. 这意味着我需要从可安装引擎访问用户身份验证数据(管理员权限等)。

I would like to know how (and if) this is possible, as it is evident that the Engine Models are accessible in the parent application it is integrated in to, but not the other way round. 我想知道这是如何(以及如果)这是可能的,因为很明显,引擎模型可以在它集成的父应用程序中访问,但不是相反。

When this question was asked here , the answer given shows how to get all data, not things from helpers (like current_user). 当被问到这个问题在这里 ,给出的答案显示了如何从助手得到的所有数据,而不是东西(如CURRENT_USER)。

When it was asked here , it seemed to cover namespacing, not the how to access functions and variables (unless I'm missing something). 当它在这里被问到时,它似乎涵盖了命名空间,而不是如何访问函数和变量(除非我遗漏了一些东西)。

Any help would be greatly appreciated. 任何帮助将不胜感激。

By design, Mountable Engines are isolated from their parent. 根据设计,可安装引擎与其父级隔离。 However, you can in theory expose portions of the parent through a REST API using ActiveResource or the like. 但是,理论上,您可以使用ActiveResource等通过REST API公开父级的部分内容。 You can also use a 'Full Engine' which acts as a sort of plugin rather than a Mountable one - Rails 3.1: Engine vs. Mountable App 你也可以使用'Full Engine'作为一种插件而不是可安装的插件 - Rails 3.1:Engine vs. Mountable App

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM