# Website Link Query

**URL:** <https://www.ruby-forum.com/t/website-link-query/69618>\
**Category:** Rails\
**Created:** [September 22, 2006, 12:50pm UTC](https://www.ruby-forum.com/t/website-link-query/69618 "2006-09-22T12:50:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [September 22, 2006, 12:50pm UTC](https://www.ruby-forum.com/t/website-link-query/69618/1 "2006-09-22T12:50:19Z")

</div>

Hi,

Say in mywebsite i have 20 pages which all use the same method to get  
some data from a model. So for example i have the follwoing  
pages(aboutus,news, resources), inside my site i would have the  
following to provide a link which uses the method page and passes the  
paramter pagename.

\<%= link\_to ‘aboutus’, :action =\> ‘page’, :pagename =\> ‘aboutus’ %\>  
\<%= link\_to ‘news’, :action =\> ‘page’, :pagename =\> ‘news’ %\>  
\<%= link\_to ‘resources’, :action =\> ‘page’, :pagename =\> ‘resources’ %\>

def page  
@information =\> Page.getinfo(params[:pagename])  
render :action =\> :pagename  
end

What the above code does is calls the same method page, gets some  
information from the pages table about that page and then displays the  
appropriate page with the information from the database.

My problem is, say i give this link to someone [www.mysite.com/aboutus](http://www.mysite.com/aboutus)  
this is not going to call the page method and get the appropriate  
information and then display the page, it will try open up the page  
without the information from the model and cause an error. This will  
look for a method called aboutus which doesnt exist. Now i cant create  
a different method for each page because pages are going to be added to  
this site quite regularily so for each new page created i would have to  
amend the controller with a method for each new page added which isnt  
what i would like.

Is it somehow possible to tell request like [www.mysite.com/aboutus](http://www.mysite.com/aboutus) to  
access the page method and use the aboutus on the end of the link to get  
the appropriate information and show the correct page?

The only possible way i can think off is to have each link access the  
page method like [www.mysite.com/page(pagenameparameter)](http://www.mysite.com/page(pagenameparameter)) and use the  
paramater as ameans of deciding which page to view, this is not an ideal  
solution.

I hope the problem is explained ok and if anyone has any suggestions i  
would be gratefull in their response.

JB

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [September 22, 2006, 7:28pm UTC](https://www.ruby-forum.com/t/website-link-query/69618/2 "2006-09-22T19:28:01Z")

</div>

You’ll want to research rails routing. The default route is of the  
form

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

So right now the only way to display your pages based on the way you’ve  
setup your controller is

[http://www.mysite.com/mycontroller/page/?page=aboutus](http://www.mysite.com/mycontroller/page/?page=aboutus) # =\> goes to  
aboutus page

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [September 22, 2006, 9:54pm UTC](https://www.ruby-forum.com/t/website-link-query/69618/3 "2006-09-22T21:54:43Z")

</div>

Brian G. wrote:

> You’ll want to research rails routing. The default route is of the  
> form
> 
> map.connect ‘:controller/:action/:id’
> 
> So right now the only way to display your pages based on the way you’ve  
> setup your controller is
> 
> [http://www.mysite.com/mycontroller/page/?page=aboutus](http://www.mysite.com/mycontroller/page/?page=aboutus) # =\> goes to  
> aboutus page

Thanks Brain, will read up on routing and decide the best approach.

Yes at the moment i have the follwoing below and although i ive seen a  
lot uglier URLs in the past hopefully there is a cleaner way of doing it  
using the routing.

[http://www.mysite.com/mycontroller/page/?page=aboutus](http://www.mysite.com/mycontroller/page/?page=aboutus)  
[http://www.mysite.com/mycontroller/page/?page=resources](http://www.mysite.com/mycontroller/page/?page=resources)  
[http://www.mysite.com/mycontroller/page/?page=news](http://www.mysite.com/mycontroller/page/?page=news)

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [September 25, 2006, 10:07am UTC](https://www.ruby-forum.com/t/website-link-query/69618/4 "2006-09-25T10:07:38Z")

</div>

On 22 Sep 2006, at 20:54, John B. wrote:

> Yes at the moment i have the follwoing below and although i ive seen a  
> lot uglier URLs in the past hopefully there is a cleaner way of  
> doing it  
> using the routing.
> 
> [http://www.mysite.com/mycontroller/page/?page=aboutus](http://www.mysite.com/mycontroller/page/?page=aboutus)  
> [http://www.mysite.com/mycontroller/page/?page=resources](http://www.mysite.com/mycontroller/page/?page=resources)  
> [http://www.mysite.com/mycontroller/page/?page=news](http://www.mysite.com/mycontroller/page/?page=news)

You may like to look at this article which describes how to set up  
routes for the ‘flat’ pages on your website, which sounds like what  
you want to do:

[http://www.paulsturgess.co.uk/articles/show/27](http://www.paulsturgess.co.uk/articles/show/27)

Your URLs will look like:

[http://www.mysite.com/aboutus](http://www.mysite.com/aboutus)  
[http://www.mysite.com/resources](http://www.mysite.com/resources)  
…

I didn’t see the original post so apologies if this is not what you  
are after.

Regards,  
Andy S.
