# Layouts

**URL:** <https://www.ruby-forum.com/t/layouts/122170>\
**Category:** Rails\
**Created:** [December 5, 2007, 5:06am UTC](https://www.ruby-forum.com/t/layouts/122170 "2007-12-05T05:06:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bernee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e9a140/32.png) [@bernee](https://www.ruby-forum.com/u/bernee)\
**Post date:** [December 5, 2007, 5:06am UTC](https://www.ruby-forum.com/t/layouts/122170/1 "2007-12-05T05:06:56Z")

</div>

I want to display the top three schools (in @top\_schools array) in my  
view which is in a column on the left on the site. This is the same for  
all views and all controllers so naturally it’s in the layout file in  
the partial \_lcol.html.erb

The problem is, being in a partial it’s displayed for whatever action it  
is in. I don’t know where to put it in the controller. Putting it in the  
index action of the Schools controller only displays the array for that  
action. How do I make it universal aside from putting the business logic  
right into the view?

\<% for school in @top\_schools %\>

- \<%= school.title %\>
  
\<% end %\>

---

<div class="post-metadata">

**Author:** ![bernee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e9a140/32.png) [@bernee](https://www.ruby-forum.com/u/bernee)\
**Post date:** [December 5, 2007, 5:08am UTC](https://www.ruby-forum.com/t/layouts/122170/2 "2007-12-05T05:08:54Z")

</div>

Put it in the application.rb file in the app/controllers directory.

On Dec 5, 2007 2:36 PM, Ellis B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> right into the view?
> 
> ## \<% for school in @top\_schools %\>
> - \<%= school.title %\>
>   
> \<% end %\>
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Ryan B.

---

<div class="post-metadata">

**Author:** ![bernee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e9a140/32.png) [@bernee](https://www.ruby-forum.com/u/bernee)\
**Post date:** [December 5, 2007, 5:16am UTC](https://www.ruby-forum.com/t/layouts/122170/3 "2007-12-05T05:16:56Z")

</div>

I tried before.  
class ApplicationController \< ActionController::Base  
@top\_schools = School.find  
end

does not make the @top\_schools variable available to the view.

---

<div class="post-metadata">

**Author:** ![bernee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e9a140/32.png) [@bernee](https://www.ruby-forum.com/u/bernee)\
**Post date:** [December 5, 2007, 5:19am UTC](https://www.ruby-forum.com/t/layouts/122170/4 "2007-12-05T05:19:30Z")

</div>

It likes it in the Application\_Helper file.

Ellis B. wrote:

> I tried before.  
> class ApplicationController \< ActionController::Base  
> @top\_schools = School.find  
> end
> 
> does not make the @top\_schools variable available to the view.

---

<div class="post-metadata">

**Author:** ![bernee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e9a140/32.png) [@bernee](https://www.ruby-forum.com/u/bernee)\
**Post date:** [December 5, 2007, 6:12am UTC](https://www.ruby-forum.com/t/layouts/122170/5 "2007-12-05T06:12:00Z")

</div>

On Dec 4, 2007, at 8:06 PM, Ellis B. wrote:

> index action of the Schools controller only displays the array for  
> that  
> action. How do I make it universal aside from putting the business  
> logic  
> right into the view?
> 
> \<% for school in @top\_schools %\>
> 
> - \<%= school.title %\>
>   
> \<% end %\>

Have a look at this article for several ideas on how to deal with  
repeating and unique partials and layouts…

[http://www.railsdev.ws/blog/3/modular-page-assembly-in-rails/](http://www.railsdev.ws/blog/3/modular-page-assembly-in-rails/)

–  
def gw  
acts\_as\_n00b  
writes\_at(www.railsdev.ws)  
end
