# accessing one controller from another

**URL:** <https://discuss.rubyonrails.org/t/accessing-one-controller-from-another/51321>\
**Category:** rubyonrails-talk\
**Created:** [April 30, 2010, 2:02pm UTC](https://discuss.rubyonrails.org/t/accessing-one-controller-from-another/51321 "2010-04-30T14:02:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [April 30, 2010, 2:02pm UTC](https://discuss.rubyonrails.org/t/accessing-one-controller-from-another/51321/1 "2010-04-30T14:02:05Z")

</div>

I have a posts controller and a pages controller for 'static' pages ie my homepage I want to have the latest post shown on the homepage.... accessing the posts controller from within the pages controller

Is there a way I can do this?

thanks

---

<div class="post-metadata">

**Author:** ![hassan](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/hassan/32/714_2.png) [@hassan](https://discuss.rubyonrails.org/u/hassan)\
**Post date:** [April 30, 2010, 2:38pm UTC](https://discuss.rubyonrails.org/t/accessing-one-controller-from-another/51321/2 "2010-04-30T14:38:42Z")

</div>

The posts controller doesn't come into the picture; just get the post info in your pages controller.

def homepage &nbsp;&nbsp;&nbsp;@post = Post.latest # assuming a named scope &nbsp;&nbsp;&nbsp;render ...

HTH,

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [April 30, 2010, 2:58pm UTC](https://discuss.rubyonrails.org/t/accessing-one-controller-from-another/51321/3 "2010-04-30T14:58:02Z")

</div>

what is render for?

---

<div class="post-metadata">

**Author:** ![shyam](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@shyam](https://discuss.rubyonrails.org/u/shyam)\
**Post date:** [April 30, 2010, 3:07pm UTC](https://discuss.rubyonrails.org/t/accessing-one-controller-from-another/51321/4 "2010-04-30T15:07:08Z")

</div>

in …/layout/application.rhtml

there will be home page \<%= render :partial =\> ‘layouts/homepage’ %\> in home page call your all pages …which u want to show

\<%= render :partial =\> ‘layouts/posts’ %\>

\<%= render :partial =\> ‘layouts/news’ %\> …etc

-Shyam

---

<div class="post-metadata">

**Author:** ![hassan](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/hassan/32/714_2.png) [@hassan](https://discuss.rubyonrails.org/u/hassan)\
**Post date:** [April 30, 2010, 3:11pm UTC](https://discuss.rubyonrails.org/t/accessing-one-controller-from-another/51321/5 "2010-04-30T15:11:27Z")

</div>

I just put that there to represent standard controller stuff -- whatever else you have in that controller method.

If you mean `what does render do?`, it's time to open the API docs 🙂

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [April 30, 2010, 3:17pm UTC](https://discuss.rubyonrails.org/t/accessing-one-controller-from-another/51321/6 "2010-04-30T15:17:51Z")

</div>

that's what I assumed but wasn't sure if you meant render a partial...

got it working now thanks!
