SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist Pixelateur's Avatar
    Join Date
    Feb 2006
    Location
    Hamburg, Germany
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Hide controller name in URL?

    Hi,

    In my new Rails project I have a controller "static" that delivers various pages to the viewer. However, the URLs Rails generates are unnecessarily long, e.g. "www.my_project.com/static/welcome" or "www.my_project.com/static/contact".

    How can I get Rails to simply hide the controller name, if the controller is "static". If the controller name is NOT "static", it should be displayed as usual.

    Can anybody help?

    Cheers!
    Last edited by PixelLover; Dec 1, 2006 at 11:04.

  2. #2
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use the routes.rb file to reroute these pages

    something like
    map.static '/contact', :controller => 'static', :action=> 'contact'
    map.static '/welcome', :controller =>'static', :action=>'welcome'

    so when someone goes to www.url.com/contact
    rails knows which controller to call.
    This still allows www.url.com/static/contact to work as well... If you really want that disabled, someone else will have to answer, because I'm not sure on that one.

    cheers
    If you give someone a program,
    you will frustrate them for a day;
    if you teach them how to program,
    you will frustrate them for a lifetime.

  3. #3
    SitePoint Evangelist Pixelateur's Avatar
    Join Date
    Feb 2006
    Location
    Hamburg, Germany
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thanks!
    Not exactly an elegant solution but it should work. I'll try it out right now. Cheers!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •