简体   繁体   English

Rails 3引擎 - 使用主应用程序中的模型?

[英]Rails 3 Engine - using models from main app?

I'm new in Rails development. 我是Rails开发的新手。 I've just created really simple Rails App and Rails Engine (which only displays static text with this example: https://github.com/mankind/Rails-3-engine-example ). 我刚刚创建了非常简单的Rails App和Rails Engine(这个例子只显示静态文本: https//github.com/mankind/Rails-3-engine-example )。 I am wondering if it is possible to use the user model from main app inside the engine. 我想知道是否可以使用引擎内主应用程序的用户模型。 If it is no clear... for example I want to get logged user data inside my engine. 如果不清楚...例如我想在我的引擎中记录用户数据。 Is it possible, and how? 有可能,怎么样?

Engine is an Rails App itself so how can I develop engine without model (for example user model) from my main app? Engine是一个Rails应用程序本身,那么如何从我的主应用程序开发没有模型的引擎(例如用户模型)? Any sugestions? 任何sugestions?

Yes it's possible like in your core app. 是的,这可能就像你的核心应用程序一样。

The code inside an engine works the same way as in the app itself so I guess you'd use before_filter to check this. 引擎内部的代码与应用程序本身的代码相同,所以我猜你会使用before_filter来检查它。

I highly recommend you use a dummy app to test the engine you are coding. 我强烈建议您使用虚拟应用来测试您正在编码的引擎。 Look at my gem here: https://github.com/apneadiving/Google-Maps-for-Rails 看看我的宝石: https//github.com/apneadiving/Google-Maps-for-Rails

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

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