How to call a controller from an app view?

Hello, I allready asked about embedding an engine view from an app view
: using partials works fine.

Now, my main app needs to ask my publish engine : give me a “news”
block. This block of datas will be embedded in the site’s main page.
What are the news, how to retrieve and how to format them is a job for
the engine.

Unfortunately I really don’t know how to achieve this. What I want to do
is calling an engine controller (which retrieve the news, then render
the view accordingly) from an app view.

Embedding “black-boxed” datas from an engine in the app (or may be into
another engine view) is certainly a common need for every engines users
and I’m pretty sure there is an elegant solution I’m been missing.

Thanks

To achieve this, your publish engine should supply a ‘news component’,
which you can render in your views with ‘render_component’. See the
Rails docs on components for more information…

  • james

On 4/7/06, Nuno [email protected] wrote:

the view accordingly) from an app view.


engine-users mailing list
[email protected]
http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org

  • J *
    ~

Thanks James, valuable answer as allways :wink:

And then comes the next (and last I hope) problem :

mysite/app/controllers/site_controller with action index
-> which render the view mysite/app/views/index.rhtml
–> which contains <%= render_component :controller =>
ArticlesController, :action => “newarticles” %>
—> which calls controller (uses_component_template_root)
MYENGINE_ROOT/app/controllers/articles_controller with action
newarticles
----> which render MYENGINE_ROOT/app/controllers/newarticles.rhtml !!!
<-- GOTCHA HERE ###

Why does it tries to find the view in this directory instead of views
directory ?

I had to use
render “…/views/newsarticles”

Any idea ? Am I doing something wrong ?

Can you submit this as a ticket? I need to add some tests to ensure
that components are being rendered from Engines properly.

  • james

On 4/7/06, Nuno [email protected] wrote:

newarticles


Posted via http://www.ruby-forum.com/.


engine-users mailing list
[email protected]
http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org

  • J *
    ~

My guess would be is that you are passing it a Model and not a string.

Try this:

render_component :controller => ‘articles_controller’, :view =>
‘newarticles’

-Nb

On 4/7/06 7:07 AM, “Nuno” [email protected] wrote:

newarticles
----> which render MYENGINE_ROOT/app/controllers/newarticles.rhtml !!!
← GOTCHA HERE ###

Why does it tries to find the view in this directory instead of views
directory ?

I had to use
render “…/views/newsarticles”

Any idea ? Am I doing something wrong ?

Nathaniel S. H. Brown                        http://nshb.net

Nathaniel B. wrote:

My guess would be is that you are passing it a Model and not a string.

Try this:

render_component :controller => ‘articles_controller’, :view =>
‘newarticles’

Got different behaviours today - I can use several parameters :
render_component :controller => ArticlesController, :action =>
“newarticles”
render_component :controller => “Articles”, :action => “newarticles”

And in articles_controller.rb no matter if I
render “newsarticles” or render “…/views/newsarticles”

I’ve restarted webrick between each change just in case…

But I can’t use
render_component :controller => ‘articles_controller’, :action =>
“newarticles”
Which produce an uninitialized constant ArticlesControllerController

Is opening a ticket still needed or these behaviours are the right ones
?