【发布时间】:2015-06-15 14:42:01
【问题描述】:
我有一个主机应用程序unicorn,型号为Article。
我还有一个挂载到名为blorgh 的主机应用程序中的引擎。它还有一个模型:Article。它是命名空间的,所以引擎的Article的表名实际上是blorgh_articles.
我想做的是:从引擎内部,我想找到所有主机应用程序的articles,然后渲染它们。
#controllers/blorgh/articles_controller.rb
require_dependency "blorgh_application_controller"
module Blorgh
class ArticlesController < ApplicationController
def index
@articles = Article.all #properly grabs all the engine's articles
@host_app_articles = main_app.Article.all # this doesn't work and I don't know why
end
...
end
end
然后是视图:
#views/blorgh/articles/index.html.erb
<p> Here I will render blorg's articles </p>
<%= render @articles %>
<p> Here I want to render the host app's articles </p>
<%= render main_app.@host_app_articles%>
所以有两个问题:
- 我似乎无法从引擎内部获取主机应用的
articles - 即使我确实从引擎内部获取了主机应用程序的
articles,我也不知道如何使用主机应用程序的部分呈现主机应用程序的文章:_article.rb。在一个普通的应用程序中,我只会做render @host_app_articles,但由于视图存在于主机应用程序中,我想我会做render main_app.@host_app_articles,但我认为这行不通。
【问题讨论】:
标签: ruby-on-rails ruby rails-engines