Rails Question

I posted this to the Chicago Ruby Users Group, but no response yet. Maybe one of the two readers of thie blog have some advice:

I'm working on a small project (5 major pages, 1 with 4 linked off, 1 with 3
linked off) and I was going to just do it all in flat html files with
dreamweaver templates (yeah, I was being kinda lazy). I got the sigle page
sections done and find out, it would really be nice to do this page in with
a database (list of new products). So I thought, hey maybe this is a good
use for rails (don't laugh! I'm desperate for an excuse).

About 1 hour I had my dreamweaver pages put into a rails project with the
layout.rhtml and the contents broken out into template files. I was nearly
giggling with joy.

I made a Page controller with these actions: index, about, contact, products
and information.

products and information needs a sidebar menu, so in those methods I
specified the name of the template to render :partial=>@submenu

I used that method for the information section which contained 3 pages.

Then I come to the product section, which has 4 sections and I did the same
thing. It worked.

(so far no database interation)

Then I thought, maybe the better design was to create a Product controller.
So I did. I set the submenu template name in the initialize method, and told
it to use layout "Page" I tweaked the link in the layout/page.rhtml to call
the Product controller. It worked.

Which is the better way or are both ways stupid and you have a better one?



Blogger Joe Clarke said...

When I am trying to deiced whether or not to create a new controller, I try to think how much functionality will take place in this controller. If you are only going to have a few methods in the new controller, then it may not be worth it and it is easier to keep everything in the same controller. At the same time if the function of this controller is very different from the other controller, such as a login page, then you should go ahead and create a new controller.

I think in your case you made the right choice to go ahead and create a new controller, since the functionally of displaying products does something very different then just serve up static pages.

Also, if you are not doing so already, take advantage of rails built in page caching, it is so easy to use, it is hard to not just love it. You just need to call the following function in your controller:
caches_page :index, :about

This will then create automatically create a static html file in your /public directory the first time you access the view. When you want rails to create a new version of this file, just delete the html file it creates.

Joe Clarke

12:21 AM  

Post a Comment

Links to this post:

Create a Link

<< Home