# Newbie question on rails development

**URL:** <https://www.ruby-forum.com/t/newbie-question-on-rails-development/146421>\
**Category:** Rails\
**Created:** [August 20, 2008, 10:10pm UTC](https://www.ruby-forum.com/t/newbie-question-on-rails-development/146421 "2008-08-20T22:10:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![codemax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/977dab/32.png) [@codemax](https://www.ruby-forum.com/u/codemax)\
**Post date:** [August 20, 2008, 10:10pm UTC](https://www.ruby-forum.com/t/newbie-question-on-rails-development/146421/1 "2008-08-20T22:10:15Z")

</div>

Hello,

Maybe someone can point me in the right direction here:

Say I’m developing a site where the main page is a sort of portal. On  
that page I’d like to display content from various controllers in my  
Rails application.

For example: The top right of the screen would have a div to login  
utilizing my Session controller. The left side of the screen would have  
a div displaying content from an RSS feed controller. There would be a  
div containing page specific navigation tabs coming from a Navigation  
controller… you get the idea…

So for example I’m thinking of having a Home or Welcome controller that  
displays views/home/index.html.erb. This inherits a layout from  
Application that gives me the top banner and footer for the site. So in  
the controller I’ll put some logic to decide which navigation div to  
display and the login div based on whether the user is logged in.

So I’m in my Home controller. I’m working with def index utilizing  
views/home/index.html.erb and i want to display content from multiple  
different controllers.

I’ve found lots of different ideas on google, but nothing rock solid.  
I’m on rails 2.1.

Any direction would be much appreciated.

---

<div class="post-metadata">

**Author:** ![codemax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/977dab/32.png) [@codemax](https://www.ruby-forum.com/u/codemax)\
**Post date:** [August 20, 2008, 10:35pm UTC](https://www.ruby-forum.com/t/newbie-question-on-rails-development/146421/2 "2008-08-20T22:35:05Z")

</div>

I personally tend to think that the Model View Controller (MVC)  
architecture provided by frameworks such as Rails is often  
misunderstood. It’s very easy to begin associating the three layers in a  
one-to-one-to-one relationship. But, that’s not really in the spirit of  
MVC. MVC is all about separating responsibilities. Models being  
responsible for persisting, calculating, and otherwise manipulating  
data, views responsible for presenting data to the users, and  
controllers to handling the “wiring” between the model and view.

Nothing in MVC says anything about these being one-to-one. I place part  
of the blame for this on overuse of scaffolding. I’m not saying there’s  
anything wrong with scaffolding, I just think it tends to promote this  
limited view of MVC.

That being said:

I would recommend deciding what pieces of view logic could be shared  
between your portal page and other views that may contain the same view  
code. Take that shared code and create a folder somewhere in your  
project structure to store partials contain these shared views (maybe  
app/views/shared).

Then wherever you want to display that view use something like render  
:partial =\> “shared/\_my\_view”

Just remember that your controller (say welcome\_controller.rb) is  
responsible for loading any data used in all these partials. For that I  
would recommend adding before\_filters to call a method to get all  
required data from your model.

It might even be worth while to look into a “Presenter” pattern  
architecture for your welcome page. I’ll leave that as an exercise for  
you to research.

Leif Elan wrote:

> Hello,
> 
> Maybe someone can point me in the right direction here:
> 
> Say I’m developing a site where the main page is a sort of portal. On  
> that page I’d like to display content from various controllers in my  
> Rails application.
> 
> For example: The top right of the screen would have a div to login  
> utilizing my Session controller. The left side of the screen would have  
> a div displaying content from an RSS feed controller. There would be a  
> div containing page specific navigation tabs coming from a Navigation  
> controller… you get the idea…
> 
> So for example I’m thinking of having a Home or Welcome controller that  
> displays views/home/index.html.erb. This inherits a layout from  
> Application that gives me the top banner and footer for the site. So in  
> the controller I’ll put some logic to decide which navigation div to  
> display and the login div based on whether the user is logged in.
> 
> So I’m in my Home controller. I’m working with def index utilizing  
> views/home/index.html.erb and i want to display content from multiple  
> different controllers.
> 
> I’ve found lots of different ideas on google, but nothing rock solid.  
> I’m on rails 2.1.
> 
> Any direction would be much appreciated.

---

<div class="post-metadata">

**Author:** ![codemax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/977dab/32.png) [@codemax](https://www.ruby-forum.com/u/codemax)\
**Post date:** [August 20, 2008, 10:38pm UTC](https://www.ruby-forum.com/t/newbie-question-on-rails-development/146421/3 "2008-08-20T22:38:23Z")

</div>

> :partial =\> “shared/\_my\_view”  
> Correction: This should be “shared/my\_view” The partial filename starts  
> with the underscore, but you don’t include that when rendering it.
