I have a host app unicorn
with the model Article
.
I also have a mountable engine hooked into the host app called blorgh
. It also has a model: Article
. It is namespaced, so the table name for the engine's Article
is actually blorgh_articles.
What I am trying to do is this: From inside the engine, I want to find all of host app's articles
and then render them.
#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
And then the view:
#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%>
So two problems going on:
- I can't seem to grab the host app's
articles
from inside the engine - Even if I did grab the host app's
articles
from inside the engine, I do not know how to render the host app's articles using the host app's partial:_article.rb
. In a normal app I would just dorender @host_app_articles
but since the view lives in the host app, I figured I would dorender main_app.@host_app_articles
but I don't think that works.
Grab the host's articles from the engine:
Render it from the view inside the engine:
And just for completion, here is what the partial might look like in the host app: