Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 605281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:07:43+00:00 2026-05-13T17:07:43+00:00

I add this line in my routes.rb file map.connect ‘:controller/:action/:id/:title’, :controller => recipes thinking

  • 0

I add this line in my routes.rb file

map.connect ':controller/:action/:id/:title', :controller => "recipes"

thinking that I am adding the recipe title at the end of the URL and this would only apply to the recipe controller. I have also declared a resource at the beginning of the file like this

map.resources :recipes

The following URL works perfectly fine

http://localhost:3000/recipes/show/84/testing201
http://localhost:3000/recipes/edit/84/testing2010

However, when I say rake routes I get the following for the recipe controller

recipes GET    /recipes(.:format)                 {:controller=>"recipes", :action=>"index"}
             POST   /recipes(.:format)                 {:controller=>"recipes", :action=>"create"}
  new_recipe GET    /recipes/new(.:format)             {:controller=>"recipes", :action=>"new"}
 edit_recipe GET    /recipes/:id/edit(.:format)        {:controller=>"recipes", :action=>"edit"}
      recipe GET    /recipes/:id(.:format)             {:controller=>"recipes", :action=>"show"}
             PUT    /recipes/:id(.:format)             {:controller=>"recipes", :action=>"update"}
             DELETE /recipes/:id(.:format)             {:controller=>"recipes", :action=>"destroy"}

and at the bottom I see this

/:controller/:action/:id/:title    
/:controller/:action/:id           
/:controller/:action/:id(.:format) 

From the output it seems like the title is not applied to the recipe route but it is applied at a global level. How can I fix this, so the wildcard symbol (“:title” in “/:controller/:action/:id/:title”) is only applicable to the recipes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:07:43+00:00Added an answer on May 13, 2026 at 5:07 pm

    You are mixing two different routing concepts. One is RESTful routes (go read about it on google) and the other is generic/general route. You should use just one of them. RESTful one is recommended (map.resources :recipes). But first you need to decide which one to use.

    Plus this definition is wrong:

    map.connect ':controller/:action/:id/:title', :controller => "recipes"
    

    You have :controller variable in the routes and then you say that :controller should be bound to ‘recipes’. One way to fix it is this:

    map.connect '/recipes/:action/:id', :controller => "recipes"
    

    or better

    map.connect '/recipes/:id/:action', :controller => "recipes"
    

    and you’re getting closer to RESTful routes.

    If you want the title in your routes, then go with named route coupled with RESTful resource. But don’t mix :id and :title in one route. Use just one parameter (or both combined but that’s another story).

    map.resources :recipes, :except => [:show]
    map.recipe '/recipe/:title', :controller => 'recipes', :action => 'show'
    

    And you would probably need to override the to_param method in your Recipe model:

    def Recipe < ActiveRecord::Base
      def to_param
         title
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this line in my .htaccess file to automatically add a trailing slash
I have added into my routes file prefix value to each map.resources line. So
In this piece of code: ActionController::Routing::Routes.draw do |map| map.resources :line_items map.resources :orders map.resources :products
I want to add share this on Facebook to a page. I've got this
This question is kind of an add-on to this question In C#, a switch
I've seen this quite a few times while using Office Interop classes this.CustomXMLParts.Add(MyResources.Data, new
This page from Adobe says to add a wmode parameter and set its value
I have this solution for a single button: myButton.Attributes.Add(onclick, this.disabled=true; + GetPostBackEventReference(myButton).ToString()); Which works
I am trying this in my Form Load Event cmdCancel.Attributes.Add(onClick, document.forms[0].reset();return false;) but it
I'm trying to add parameters to an objectDataSource at runtime like this: Parameter objCustomerParameter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.