Forum: Rails Engines How to call a controller from an app view ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A5d8283732da86365736508fef6c1c67?d=identicon&s=25 Nuno (Guest)
on 2006-04-07 14:59
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
05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 James Adam (Guest)
on 2006-04-07 15:10
(Received via mailing list)
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 <nomail@atall.com> wrote:
> the view accordingly) from an app view.
> _______________________________________________
> engine-users mailing list
> engine-users@lists.rails-engines.org
> http://lists.rails-engines.org/listinfo.cgi/engine...
>


--
* J *
  ~
A5d8283732da86365736508fef6c1c67?d=identicon&s=25 Nuno (Guest)
on 2006-04-07 16:07
Thanks James, valuable answer as allways ;-)

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 ?
05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 James Adam (Guest)
on 2006-04-07 16:18
(Received via mailing list)
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 <nomail@atall.com> wrote:
> newarticles
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> engine-users mailing list
> engine-users@lists.rails-engines.org
> http://lists.rails-engines.org/listinfo.cgi/engine...
>


--
* J *
  ~
00e3a96684ab390a350b0271e98741d3?d=identicon&s=25 Nshbrown Nshbrown (nshb)
on 2006-04-08 16:02
(Received via mailing list)
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" <nomail@atall.com> 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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A5d8283732da86365736508fef6c1c67?d=identicon&s=25 Nuno (Guest)
on 2006-04-08 18:19
Nathaniel Brown 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
?
This topic is locked and can not be replied to.