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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:48:02+00:00 2026-05-12T14:48:02+00:00

I’m trying to create a nested resource with a url scheme along the lines

  • 0

I’m trying to create a nested resource with a url scheme along the lines of: “http://example.com/username/...“.

What I currently have is this:

ActionController::Routing::Routes.draw do |map|
  map.home '/', :controller => 'home'

  map.resource :session

  map.resources :users, :has_many => :nodes
  #map.user '/:id', :controller => 'users', :action => 'show', :has_many => :nodes

  map.resources :nodes, :belongs_to => :user
end

This results in URLs like:

http://example.local/users/username
http://example.local/users/username/nodes

How to avoid the “users” prefix is beyond me. Passing a “as: => ''” option to map.resources doesn’t work and it seems named routes don’t support the “:has_many” or “:belongs_to” options.

Commenting out the “map.resources :users” and uncommmenting the “map.user” line after it seems to work… until you reach a nested resource. Then it spits out the following error:

undefined method `user_nodes_path' for #<ActionView::Base:0x1052c8d18>

I know this problem has come up plenty of times before and is always met with “Why would you want to do that?” responses. Frankly, Twitter does it, Facebook does it, and I want to do it too! ;-D

As for the common criticism of how to avoid usernames from conflicting built-in paths, I’ve set my minimum username length to 6 characters and plan to make all built-in root-level paths segments paths 5 characters or shorter (i.e. “/opt/...” for options, “/in/...” for session log-in, etc.).

  • 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-12T14:48:07+00:00Added an answer on May 12, 2026 at 2:48 pm

    As noted in this question:

    Default segment name in rails resources routing

    You should be able to use this plugin:

    http://github.com/caring/default_routing

    Alternatively, you could specify them manually with something like

    map.users     '/users',     :controller => 'users', :action => 'index',
      :conditions => { :method => :get }
    map.connect   '/users',     :controller => 'users', :action => 'create',
      :conditions => { :method => :post }
    map.user      '/:id',       :controller => 'users', :action => 'show',
      :conditions => { :method => :get }
    map.edit_user '/:id/edit',  :controller => 'users', :action => 'edit',
      :conditions => { :method => :get }
    map.new_user  '/users/new', :controller => 'users', :action => 'new',
      :conditions => { :method => :get }
    map.connect   '/:id', :controller => 'users', :action => 'update',
      :conditions => { :method => :put }
    map.connect   '/:id', :controller => 'users', :action => 'destroy',
      :conditions => { :method => :delete }
    
    map.resources :nodes, :path_prefix => '/:user_id', :name_prefix => 'user_'
    # to generate user_nodes_path and user_node_path(@node) routes
    

    That or something like it should give you what you want from map.resources.

    map.resources doesn’t work and it seems named routes don’t support the “:has_many” or “:belongs_to” options.

    Named routes supports has_many, which is used to add another resource level to the URL path. For example

    map.resources :users, :has_many => :nodes
    

    generates all the users_path and user_nodes_path routes like /users, /users/:id, /users/:id/nodes and /users/:id/nodes/:id. It’s identical to

    map.resources :users do |user|
      user.resources :nodes
    end
    

    Commenting out the “map.resources :users” and uncommmenting the “map.user” line after it seems to work… until you reach a nested resource. Then it spits out the following error:

    undefined method `user_nodes_path' for #<ActionView::Base:0x1052c8d18>
    

    That’s because map.resources :users, :has_many => :nodes generates these routes. Only one named route is generated by map.user '/:id', :controller => 'users', :action => 'show' and that’s user_path.

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

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,

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.