# Is this the "right way"?

**URL:** <https://www.ruby-forum.com/t/is-this-the-right-way/76267>\
**Category:** Rails\
**Created:** [November 17, 2006, 2:54am UTC](https://www.ruby-forum.com/t/is-this-the-right-way/76267 "2006-11-17T02:54:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 17, 2006, 2:54am UTC](https://www.ruby-forum.com/t/is-this-the-right-way/76267/1 "2006-11-17T02:54:49Z")

</div>

The site I’m currently designing doesn’t have a db back end. So I’m  
using rails primarily for templating and some scripting.

I approached this by creating a controller called ‘main’ and various  
views like “index”, “welcome”, “about”, etc.

But then I’d get URL’s like [www.mydomain.com/main/welcome](http://www.mydomain.com/main/welcome) when I wanted  
www.mydomain/welcome.

To fix it, I made some routes in my config/routes.rb that look like:

map.connect “welcome”, :controller =\> “main”, :action =\> “welcome”

This seems to work peachy, but I was wondering…is this the “correct”  
way to approach this site design with rails?

e.g. a ‘main’ site controller and address rewrites via routes.rb?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 17, 2006, 2:59am UTC](https://www.ruby-forum.com/t/is-this-the-right-way/76267/2 "2006-11-17T02:59:29Z")

</div>

krunk- wrote:

> The site I’m currently designing doesn’t have a db back end. So I’m  
> using rails primarily for templating and some scripting.
> 
> I approached this by creating a controller called ‘main’ and various  
> views like “index”, “welcome”, “about”, etc.
> 
> But then I’d get URL’s like [www.mydomain.com/main/welcome](http://www.mydomain.com/main/welcome) when I wanted  
> www.mydomain/welcome.
> 
> To fix it, I made some routes in my config/routes.rb that look like:
> 
> map.connect “welcome”, :controller =\> “main”, :action =\> “welcome”
> 
> This seems to work peachy, but I was wondering…is this the “correct”  
> way to approach this site design with rails?
> 
> e.g. a ‘main’ site controller and address rewrites via routes.rb?

Yup, nothing wrong with this approach AFAIK.

jp

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 17, 2006, 3:50am UTC](https://www.ruby-forum.com/t/is-this-the-right-way/76267/3 "2006-11-17T03:50:56Z")

</div>

On 11¿ù17ÀÏ, ¿ÀÀü10½Ã53ºÐ, “krunk-” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> map.connect “welcome”, :controller =\> “main”, :action =\> “welcome”
> 
> This seems to work peachy, but I was wondering…is this the “correct”  
> way to approach this site design with rails?
> 
> e.g. a ‘main’ site controller and address rewrites via routes.rb?

map.connect ‘’, :controller =\> “post”, :action =\> ‘index’

map.connect ‘:id’, :controller =\> ‘post’, :action=\> ‘show’, :id =\>  
/\d+/

map.connect ‘:action/:id’, :controller =\> ‘post’ # Is it that you  
want?

# Install the default route as the lowest priority.

map.connect ‘:controller/:action/:id’

These setting set post controller default that is my forum software  
default controller.

[http://mysite/](http://mysite/)  
[http://mysite/action/](http://mysite/action/)  
[http://mysite/action/id/whatever](http://mysite/action/id/whatever)  
[http://mysite/other\_controller/action/](http://mysite/other_controller/action/)…

–  
¸¶ÀÕ(Mait)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 17, 2006, 4:14am UTC](https://www.ruby-forum.com/t/is-this-the-right-way/76267/4 "2006-11-17T04:14:59Z")

</div>

others may make a more pententrating comment, however, the ROR API is  
engineered for 2-tuples (x,y) where x desginates a controller and y  
designates an action on the controller. this is the natural way to  
approach ROR development.
