Forum: Ruby on Rails Simple Controller/Routes Question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9e7cdfa62c6bc2a155f2f7950484e573?d=identicon&s=25 Brandon S. (deniedlates)
on 2006-04-21 06:27
This is probably a very basic question, but what is the proper
controller & routing setup if I'm setting up a RoR site with static
pages, like:

http://mysite.com/about
http://mysite.com/services
http://mysite.com/contact

I want each of these pages to use a single template file that I can push
content to.  It seems like overkill to create individual controllers for
about, services, and contact, so what is the best way to set this up?
30269682335f1fb247d71969fa715b5e?d=identicon&s=25 Roberto Saccon (rsaccon)
on 2006-04-21 06:38
(Received via mailing list)
You either configure routes mapping (routes.rb) and use just one
controller
and define in each action a diferent template with the render command or
you
create differnt controllers, which is much simpler.

It mainly depends on how you want to group things together.
59ea1b450935b9d70abfec4186b7a4d5?d=identicon&s=25 Jeff Coleman (progressions)
on 2006-04-21 07:16
Brandon S. wrote:
> This is probably a very basic question, but what is the proper
> controller & routing setup if I'm setting up a RoR site with static
> pages, like:
>
> http://mysite.com/about
> http://mysite.com/services
> http://mysite.com/contact
>
> I want each of these pages to use a single template file that I can push
> content to.  It seems like overkill to create individual controllers for
> about, services, and contact, so what is the best way to set this up?

What I've done is create a simple controller called "site" which will
group all my contact/about/privacy terms/etc pages together.  Then I use
routes to direct "/about" to "/site/about":

	map.contact '/contact', :controller => 'site', :action => 'contact'
	map.about '/about', :controller => 'site', :action => 'about'
	map.terms '/terms', :controller => 'site', :action => 'terms'
	map.privacy '/privacy', :controller => 'site', :action => 'privacy'

Jeff Coleman
9e7cdfa62c6bc2a155f2f7950484e573?d=identicon&s=25 Brandon S. (deniedlates)
on 2006-04-21 07:19
Roberto,

Thanks for the info... I would like to have one design template and push
content from each page to the template, so it seems like the single
controller is the way to go... does anyone have other thoughts?

Brandon
9e7cdfa62c6bc2a155f2f7950484e573?d=identicon&s=25 Brandon S. (deniedlates)
on 2006-04-21 07:22
Jeff Coleman wrote:
>
> What I've done is create a simple controller called "site" which will
> group all my contact/about/privacy terms/etc pages together.  Then I use
> routes to direct "/about" to "/site/about":
>
> 	map.contact '/contact', :controller => 'site', :action => 'contact'
> 	map.about '/about', :controller => 'site', :action => 'about'
> 	map.terms '/terms', :controller => 'site', :action => 'terms'
> 	map.privacy '/privacy', :controller => 'site', :action => 'privacy'
>
> Jeff Coleman

Jeff... awesome!  That sounds like a good solution.  I'll try it out.
This topic is locked and can not be replied to.