# How to create an index page with data from other contollers

**URL:** <https://www.ruby-forum.com/t/how-to-create-an-index-page-with-data-from-other-contollers/185465>\
**Category:** Rails\
**Created:** [March 20, 2010, 5:58pm UTC](https://www.ruby-forum.com/t/how-to-create-an-index-page-with-data-from-other-contollers/185465 "2010-03-20T17:58:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![graham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4af34b/32.png) [@graham](https://www.ruby-forum.com/u/graham)\
**Post date:** [March 20, 2010, 5:58pm UTC](https://www.ruby-forum.com/t/how-to-create-an-index-page-with-data-from-other-contollers/185465/1 "2010-03-20T17:58:41Z")

</div>

Hi all,

First I’m new to RoR so if I’m asking a question thats simple sorry but  
I can’t find the answer on google.

I have a number of controllers that are working fine and I’ve got the  
foreign keys etc working.

What I’m looking to do now is have an index page that will have  
information displayed from lets say 3 of these controllers on the page  
with links to other pages.

Can I ask someone to point me in the right direction, do I have to  
create a new controller for this (surely not as this goes against DRY)

Thanks,

Graham

---

<div class="post-metadata">

**Author:** ![graham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4af34b/32.png) [@graham](https://www.ruby-forum.com/u/graham)\
**Post date:** [March 21, 2010, 9:28am UTC](https://www.ruby-forum.com/t/how-to-create-an-index-page-with-data-from-other-contollers/185465/2 "2010-03-21T09:28:06Z")

</div>

Hiya Graham,

It depends on your setup really but I would say in this case you would  
want another controller.

If you’ve put all the shared html into partials then on the new index  
page you would just need to do a few \<%= render :partial =\>  
‘PARTIAL\_NAME’%\> to pull in the html you need.

[http://api.rubyonrails.org/classes/ActionView/Partials.html](http://api.rubyonrails.org/classes/ActionView/Partials.html)

> **[Layouts and Rendering in Rails — Ruby on Rails Guides](https://guides.rubyonrails.org/layouts_and_rendering.html#using-partials)**
>
> Layouts and Rendering in RailsThis guide covers the basic layout features of Action Controller and Action View.After reading this guide, you will know: How to use the various rendering methods built into Rails. How to create layouts with multiple...

Cheers  
Luke

---

<div class="post-metadata">

**Author:** ![graham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4af34b/32.png) [@graham](https://www.ruby-forum.com/u/graham)\
**Post date:** [March 21, 2010, 9:52pm UTC](https://www.ruby-forum.com/t/how-to-create-an-index-page-with-data-from-other-contollers/185465/3 "2010-03-21T21:52:23Z")

</div>

Luke P. wrote:

> Hiya Graham,
> 
> It depends on your setup really but I would say in this case you would  
> want another controller.
> 
> If you’ve put all the shared html into partials then on the new index  
> page you would just need to do a few \<%= render :partial =\>  
> ‘PARTIAL\_NAME’%\> to pull in the html you need.
> 
> [http://api.rubyonrails.org/classes/ActionView/Partials.html](http://api.rubyonrails.org/classes/ActionView/Partials.html)
> 
> [Layouts and Rendering in Rails — Ruby on Rails Guides](http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials)
> 
> Cheers  
> Luke

Thanks for the advice Luke I’ll use a new controller for the index page  
as some of the other pages don’t have partials.  
Can I ask how I can link the contollers should I include attributes from  
the other controllers index defs etc, such as

myindexcontroller

```
 def index

        @Businesss = Business.all #from the business controller

        <html to show business list>

      end

```

end

cheers,

Graham

---

<div class="post-metadata">

**Author:** ![graham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4af34b/32.png) [@graham](https://www.ruby-forum.com/u/graham)\
**Post date:** [March 22, 2010, 11:43am UTC](https://www.ruby-forum.com/t/how-to-create-an-index-page-with-data-from-other-contollers/185465/4 "2010-03-22T11:43:03Z")

</div>

On 21 March 2010 20:52, Graham F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > [http://api.rubyonrails.org/classes/ActionView/Partials.html](http://api.rubyonrails.org/classes/ActionView/Partials.html)  
> > the other controllers index defs etc, such as
> 
> myindexcontroller
> 
> ```
> def index
> 
> @Businesss = Business.all #from the business controller
> 
> ```

Business.all is not from the business controller, it is the Business  
model. You can call this from any controller.

Colin
