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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:35:15+00:00 2026-05-18T04:35:15+00:00

I have a set of nested resources — :users and :messages. resources :users, :only

  • 0

I have a set of nested resources — :users and :messages.

  resources :users, :only => [:show,:index] do
    resources :messages
  end

And also a formtastic form in the “new.html.haml” template for the Message model and it needs to use these resources:

=semantic_form_for [@user,@message] do |f|
 =f.input :title

The problem is in the actual action path that is generated from [@user,@message], and it looks like this:

/users/4cdc7f9dfae434029a0000aa/messages

This is wrong because I am using a named route, so this should look like “/users/nickname/messages”

How can I make sure that @user produces a proper path output?

Edit: Here is the name routes I am using to slugify the user.

  match "/users/:nickname/messages" => "messages#index"
  match "/users/:nickname/messages/new" => "messages#new", :as=>:new_message
  match "/users/:nickname/messages" => "messages#create", :as=>:create_message
  • 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-18T04:35:16+00:00Added an answer on May 18, 2026 at 4:35 am

    I guess what you want is to use the nickname as the url slug. What you need for that is just the regular nested resources;

    # in routes.rb
    
    resources :users do
      resources :messages
    end
    

    which would give you the same routes except they would have :id instead of :nickname in there.

    Now for the actual trick that lets you use the user’s nickname as the url identifier:

    # user.rb
    
    class User < ActiveRecord::Base
      def to_param
        self.nickname
      end
    end
    

    You would automatically get the nickname in the url, and have it passed on to your controllers as params[:id] so you have to act accordingly in your controller

    # users_controller.rb
    …
    def show
      @user = User.find_by_nickname(params[:id])
    end
    …
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a nested resource in my routes.rb like this: map.resources :users, :only =>
In Rails 3 edge, I have set up two nested resources like this: config/routes.rb
To set up nested resources in Rails, I have seen example routes given like
I have a set of nested Ant build files, and I need to control
I have a set of nested DIVs that slidetoggle using jQuery as the user
We have set up a system where notifications get sent to a user with
I have set a canvas' background to an image of a company logo. I
I have set up transactional replication between two SQL Servers on different ends of
I have set up a version control system using TortoiseSVN at my home to
I have set up a Django application that uses images. I think I have

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.