Lots of views for a single controller

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

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
[email protected]

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

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.