# How to call a controller from an app view?

**URL:** <https://www.ruby-forum.com/t/how-to-call-a-controller-from-an-app-view/57145>\
**Category:** Engines\
**Created:** [April 7, 2006, 2:59pm UTC](https://www.ruby-forum.com/t/how-to-call-a-controller-from-an-app-view/57145 "2006-04-07T14:59:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nuno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/65b543/32.png) [@nuno](https://www.ruby-forum.com/u/nuno)\
**Post date:** [April 7, 2006, 2:59pm UTC](https://www.ruby-forum.com/t/how-to-call-a-controller-from-an-app-view/57145/1 "2006-04-07T14:59:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nuno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/65b543/32.png) [@nuno](https://www.ruby-forum.com/u/nuno)\
**Post date:** [April 7, 2006, 3:10pm UTC](https://www.ruby-forum.com/t/how-to-call-a-controller-from-an-app-view/57145/2 "2006-04-07T15:10:36Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> the view accordingly) from an app view.
> 
> * * *
> 
> engine-users mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org](http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org)

–

- J \*  
~

---

<div class="post-metadata">

**Author:** ![nuno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/65b543/32.png) [@nuno](https://www.ruby-forum.com/u/nuno)\
**Post date:** [April 7, 2006, 4:07pm UTC](https://www.ruby-forum.com/t/how-to-call-a-controller-from-an-app-view/57145/3 "2006-04-07T16:07:29Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![nuno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/65b543/32.png) [@nuno](https://www.ruby-forum.com/u/nuno)\
**Post date:** [April 7, 2006, 4:18pm UTC](https://www.ruby-forum.com/t/how-to-call-a-controller-from-an-app-view/57145/4 "2006-04-07T16:18:16Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> newarticles
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> engine-users mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org](http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org)

–

- J \*  
~

---

<div class="post-metadata">

**Author:** ![nuno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/65b543/32.png) [@nuno](https://www.ruby-forum.com/u/nuno)\
**Post date:** [April 8, 2006, 4:02pm UTC](https://www.ruby-forum.com/t/how-to-call-a-controller-from-an-app-view/57145/5 "2006-04-08T16:02:56Z")

</div>

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” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 ?

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

```

---

<div class="post-metadata">

**Author:** ![nuno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/65b543/32.png) [@nuno](https://www.ruby-forum.com/u/nuno)\
**Post date:** [April 8, 2006, 6:19pm UTC](https://www.ruby-forum.com/t/how-to-call-a-controller-from-an-app-view/57145/6 "2006-04-08T18:19:47Z")

</div>

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  
?
