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 7073073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:53:08+00:00 2026-05-28T05:53:08+00:00

I have Users, Bands and Codes Bands have many Codes, Users have many codes,

  • 0

I have Users, Bands and Codes

Bands have many Codes, Users have many codes, but Users and Bands don’t have any relationship.

Bands have many codes because users create codes that are related to a band. There may be many bands for which a user has codes for…

I guess a user could have a band but I do not want my urls to be users/:id/bands/:id/codes/:id

Ideas?

  • 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-28T05:53:09+00:00Added an answer on May 28, 2026 at 5:53 am

    EDIT: I just noticed that your question says you do not want that url. My answer is the reverse, sorry.

    If that’s what want your url to be, then you should definitely make Users have many Bands, and Bands have many Codes. Then use a has_many :though to make Users have many Codes. Like this:

    class Code < ActiveRecord::Base
      belongs_to :band
      belongs_to :user, :through => :band
    end
    
    class Band < ActiveRecord::Base
      has_many :codes
      belongs_to :user
    end
    
    class User < ActiveRecord::Base
      has_many :bands
      has_many :codes, :through => :bands
    end
    

    Then set up your routes using nested resources:

    map.resources :users do |users|
      users.resources :bands do |bands|
        bands.resources :codes
        end
      end
    end
    

    That would make code_path(1, 2, 3) map to /users/1/bands/2/codes/3. And your CodesController#show action would have access to user_id (1), band_id (2), and id (3).

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

Sidebar

Related Questions

I have Users Bands and Codes. A user creates a code and that code
We frequently have users that create multiple accounts and then end up storing the
I have Bands and Codes and Users. the key/codes will let a user do
I have users table. There are three other tables: developers, managers, testers. All of
One problem that I come across regularly and yet don't have a solution to
I have a command that binds to the view model, is enabled, but doesn't
I have a scenario that does not seem to be covered in any of
I have a WPF User control that binds to a DataTable and generates CheckBox
I have users who are using secure-wave security. Evidently it is some sort of
i have users table and i have posts table i want select from users

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.