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

  • Home
  • SEARCH
  • 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 5841505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:53:56+00:00 2026-05-22T11:53:56+00:00

I have a group model which has_many article model. And I want to use

  • 0

I have a group model which has_many article model. And I want to use the following url pattern “{group_id}/{article_id}”.

so I wrote these route codes:

resource :groups do
  resource :articles
end
match ':group_id/:id(.:format)', :to => 'articles#show', :as => :article
match ':id', :to => 'groups#show', :as => :group

But rails fail to generate correct url for group records and article records. How can I replace the automatic generated article_path and group_path to match my routes?

  • 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-22T11:53:56+00:00Added an answer on May 22, 2026 at 11:53 am

    You’re running into problems because you aren’t watching out for pluralization. When you define a singular resource route, Rails doesn’t treat it as a collection where you would refer to each member with an id. You instead want a plural resources for both groups and articles:

    resources :groups do
      resources :articles
    end
    

    Generates the following routes:

        group_articles GET    /groups/:group_id/articles(.:format)          {:action=>"index", :controller=>"articles"}
                       POST   /groups/:group_id/articles(.:format)          {:action=>"create", :controller=>"articles"}
     new_group_article GET    /groups/:group_id/articles/new(.:format)      {:action=>"new", :controller=>"articles"}
    edit_group_article GET    /groups/:group_id/articles/:id/edit(.:format) {:action=>"edit", :controller=>"articles"}
         group_article GET    /groups/:group_id/articles/:id(.:format)      {:action=>"show", :controller=>"articles"}
                       PUT    /groups/:group_id/articles/:id(.:format)      {:action=>"update", :controller=>"articles"}
                       DELETE /groups/:group_id/articles/:id(.:format)      {:action=>"destroy", :controller=>"articles"}
                groups GET    /groups(.:format)                             {:action=>"index", :controller=>"groups"}
                       POST   /groups(.:format)                             {:action=>"create", :controller=>"groups"}
             new_group GET    /groups/new(.:format)                         {:action=>"new", :controller=>"groups"}
            edit_group GET    /groups/:id/edit(.:format)                    {:action=>"edit", :controller=>"groups"}
                 group GET    /groups/:id(.:format)                         {:action=>"show", :controller=>"groups"}
                       PUT    /groups/:id(.:format)                         {:action=>"update", :controller=>"groups"}
                       DELETE /groups/:id(.:format)                         {:action=>"destroy", :controller=>"groups"}
    

    If you want to leave off the groups and articles segments you can pass :path => '' to each of the resources definitions, but you are going to have to tread carefully because any request to http://example.com/1/2 will map to an article under groups and be uninformative to end users and bots alike.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following entities in my domain model. A group (an aggregate root)
I have models (simplified example): class Group(models.Model): name = models.CharField(max_length = 32) class Person(models.Model):
I have a group of checkboxes that I only want to allow a set
I have an application which I am trying to design using the MVVM pattern.
I have a model, Rating , which looks something like this: class Rating(models.Model): upvotes
I have a group of strings in Javascript and I need to write a
We have a group of a few developers and some business analysts. We as
At my company we have a group of 8 web developers for our business
I have two tables Group and Customer and of course two entities Group and
Background: We have an offshore group working up a Silverlight 2 prototype for us.

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.