SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Addict JNKlein's Avatar
    Join Date
    Sep 2004
    Location
    New York, NY
    Posts
    258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [RoR] rewrite changes?

    im developing a controller that will be passed a variable through the url string

    normally it would appear as
    example.com/controller/action1
    or
    example.com/controller/action2

    but I want this particular controller to look like:
    example.com/action1/controller
    or
    example.com/action2/controller

    but not all my controllers are like that, so I don't want to change the rewrite rules in apache. Can i do this through RoR? How?

    Thanks.

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do something like this in config/routes.rb:
    Code:
    map.connect ':action/:controller', :requirements => { :controller => /^only_this_controller$/ }

  3. #3
    SitePoint Addict JNKlein's Avatar
    Join Date
    Sep 2004
    Location
    New York, NY
    Posts
    258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks - worked like a charm

    its neat, and very useful, that you can have :requirements => { :controller => /any_regex_you_want/ }

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea its really great. You can learn more about routing here:
    http://manuals.rubyonrails.com/read/chapter/65



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
  •