# Lots of views for a single controller

**URL:** <https://www.ruby-forum.com/t/lots-of-views-for-a-single-controller/187603>\
**Category:** Rails\
**Created:** [April 26, 2010, 7:10pm UTC](https://www.ruby-forum.com/t/lots-of-views-for-a-single-controller/187603 "2010-04-26T19:10:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![richardsugg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@richardsugg](https://www.ruby-forum.com/u/richardsugg)\
**Post date:** [April 26, 2010, 7:10pm UTC](https://www.ruby-forum.com/t/lots-of-views-for-a-single-controller/187603/1 "2010-04-26T19:10:54Z")

</div>

I’m new to rails and would like some guidance on how to proceed. It’s  
kind of hard to hold the entire framework in my head and work through  
an issue, but if you can give me the high-level concepts, I should be  
able to work through this.

I have a customer database where I store information such as contacts,  
remote access, server information, upgrade history, notes, etc. I  
would like a webpage that contains tabs for each of the aforementioned  
sections. So it would seem like I would have the following (I’m only  
concerning myself with the Company section for now):

Models: Company, server, notes, etc.  
Controllers: Company  
Layout: application.rhtml to handle the main framework

Assuming the above is correct, I’m really struggling with how to make  
the templates:  
Templates: (all views are company templates)

- show\_general.html.erb # shows general information (remote access,  
company name, active or not, etc)  
\<%= render ‘company/company\_header’ %\>  
\<%= render ‘company/general’ %\>  
the \_company\_header just shows the company name as a header  
\_general should show/edit the general information about the company

- repeat for all other sections

So does this make sense? Am I taking the right approach?

Thanks,  
Richard

---

<div class="post-metadata">

**Author:** ![richardsugg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@richardsugg](https://www.ruby-forum.com/u/richardsugg)\
**Post date:** [April 26, 2010, 10:46pm UTC](https://www.ruby-forum.com/t/lots-of-views-for-a-single-controller/187603/2 "2010-04-26T22:46:06Z")

</div>

richardsugg wrote:

> I’m new to rails and would like some guidance on how to proceed. It’s  
> kind of hard to hold the entire framework in my head and work through  
> an issue, but if you can give me the high-level concepts, I should be  
> able to work through this.

Have you read the Rails Guides?

> I have a customer database where I store information such as contacts,  
> remote access, server information, upgrade history, notes, etc. I  
> would like a webpage that contains tabs for each of the aforementioned  
> sections. So it would seem like I would have the following (I’m only  
> concerning myself with the Company section for now):
> 
> Models: Company, server, notes, etc.  
> Controllers: Company  
> Layout: application.rhtml to handle the main framework

Not .rhtml, unless you’re using Rails 1.x (and you shouldn’t be). In  
current versions of Rails, view extensions work differently. Please  
follow a current tutorial or reference.

> Assuming the above is correct, I’m really struggling with how to make  
> the templates:  
> Templates: (all views are company templates)
> 
> - show\_general.html.erb # shows general information (remote access,  
> company name, active or not, etc)  
> \<%= render ‘company/company\_header’ %\>  
> \<%= render ‘company/general’ %\>  
> the \_company\_header just shows the company name as a header  
> \_general should show/edit the general information about the company

Those should be render :partial.

> - repeat for all other sections
> 
> So does this make sense? Am I taking the right approach?

I don’t know. You’ve described your data, but haven’t said what you’re  
trying to do with it.

> Thanks,  
> Richard

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![richardsugg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@richardsugg](https://www.ruby-forum.com/u/richardsugg)\
**Post date:** [April 27, 2010, 5:58pm UTC](https://www.ruby-forum.com/t/lots-of-views-for-a-single-controller/187603/3 "2010-04-27T17:58:26Z")

</div>

Thanks very much for both of your assistance. I think I’ve got a  
handle on the immediate issue as a result.

---

<div class="post-metadata">

**Author:** ![richardsugg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@richardsugg](https://www.ruby-forum.com/u/richardsugg)\
**Post date:** [April 27, 2010, 2:09pm UTC](https://www.ruby-forum.com/t/lots-of-views-for-a-single-controller/187603/4 "2010-04-27T14:09:32Z")

</div>

richardsugg wrote:

> - show\_general.html.erb # shows general information (remote access,  
> company name, active or not, etc)

To keep things simple, show is just show… and can render the data you  
want to have constant across any variations - no need for a header  
partial there. But a different partial per ‘tab’ works.

For simplicity in v1.0, you might make those ‘tabs’ a row of hyperlinks  
back to the show method with a param that designates which partial to  
display for now. Yes, it is a round-trip to refresh that data, but “I’m  
new to rails” means take things in bite-sized chunks. Later  
(seriously… after you have things looking and behaving the way you  
want, and begin to grok the framework), you’ll want to look into Ajax  
for that behavior.

Rather than trying to design the whole ‘grand scheme’ now, pick one view  
of your set (let’s pick the company contact) and get that form working.  
From there, you can tinker with layout until you have the header and  
menus you want and can start thinking about your partials to display  
different information.

Once you get your first fork in display behavior done, it should be a  
piece of cake to add as many as you need to fill out the rest of the  
company views.

From there, extend to other models, controllers, and joins.
