Simple rails website design question

I want to make a simple website with rails, but I'm confused about how to setup my controllers. Here's what I want:

5 pages: Home, Products & Services, Press Center, White Papers & About us

So, I'm confused about how to set this up. Should each page have it's own controller, e.g.:

home_controller, products_controller, press_controller, white_papers_controller and about_us_controller

Is this a wise design decision?

I would like to use a layout "template" for all the pages. How then, if I'm using independent controllers for each page do I share a layout?

All the rails site examples I've found are kinda non-standard sites with only 1 real page, like a shopping cart, so I'm not sure how to structure my rails app for a site with many pages.

Can you cite any examples?

Well, all of the pages are pretty much standard, read an object from the database then databind the page. SO that would fit into your one controller idea with many actions for each page.

I would like my urls to look like this:

www.domain_name.com/products www.domain_name.com/whitepapers www.domain_name.com/about

etc...

Without any modifications to my routes.rb file the only way to access my pages is to refrene the controller in the path like:

www.domain_name.com/base/products

How do I set up my urls to work like my list above?

I want to make a simple website with rails, but I'm confused about how to setup my controllers. Here's what I want:

5 pages: Home, Products & Services, Press Center, White Papers & About us

So, I'm confused about how to set this up. Should each page have it's own controller, e.g.:

home_controller, products_controller, press_controller, white_papers_controller and about_us_controller

Is this a wise design decision?

Can't tell, with the information given.

The very "general" rule is to have a controller per model, so that's a good place to start. But it's not necessary to agonize over the structure of your controllers. Rather than trying to envision how the whole thing will look like when it's done, just implement a very small part of it. Start with one controller. Then when you need to add stuff, you have a choice: do I add an action to my current controller or do I create a new controller? Well, make your best guess and see how that goes. If it turns out to be problematic for whatever reason, it's easy to back up and take the other direction.

Also, don't agonize over what the url's look like. You can use routes to map any kind of urls to any kind of controller structure.

I would like to use a layout "template" for all the pages. How then, if I'm using independent controllers for each page do I share a layout?

By default, all controllers will use the layout in app/views/layouts/application.rhtml. So put your template there and you're done.

Add a line to routes.rb

map.connect(“:action/:id”, :controller => “base_controller”)

One more thing:

What you said takes care of most of the urls:

www.domain_name.com/products www.domain_name.com/whitepapers www.domain_name.com/about

but I would like to access whitepapers like this:

www.domain_name.com/whitepapers/1 www.domain_name.com/whitepapers/3 ... www.domain_name.com/whitepapers/[WhitePaper.id]

How would I set this url structure up?

It should already work. params[:id] should contain the 1 or the 3 in the examples you gave.

then in the controller you’d do something like

wp = WhitePaper.find_by_id(params[:id].to_i)

Bob Showalter wrote:

  

I want to make a simple website with rails, but I'm confused about how to setup my controllers. Here's what I want:

5 pages: Home, Products & Services, Press Center, White Papers & About us

So, I'm confused about how to set this up. Should each page have it's own controller, e.g.:

home_controller, products_controller, press_controller, white_papers_controller and about_us_controller

Is this a wise design decision?      Can't tell, with the information given.

The very "general" rule is to have a controller per model, so that's a good place to start. But it's not necessary to agonize over the structure of your controllers. Rather than trying to envision how the whole thing will look like when it's done, just implement a very small part of it. Start with one controller. Then when you need to add stuff, you have a choice: do I add an action to my current controller or do I create a new controller? Well, make your best guess and see how that goes. If it turns out to be problematic for whatever reason, it's easy to back up and take the other direction.

Also, don't agonize over what the url's look like. You can use routes to map any kind of urls to any kind of controller structure.

I would like to use a layout "template" for all the pages. How then, if I'm using independent controllers for each page do I share a layout?      By default, all controllers will use the layout in app/views/layouts/application.rhtml. So put your template there and you're done.    I know this reply is quite far down in the thread but have you considered using a Content Management System like Radiant? Based on the scarce requirements in the OP's email, it would appear that if most of the pages are largely static (like a company website), Radiant would be quite good!

Cheers, Mohit. 9/14/2007 | 12:52 AM.

ahh, it looks like it does. Thanks. It seems like the single controller with actions for each page will work fine for me.

Thanks, I'll check it out.