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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:39:19+00:00 2026-05-16T07:39:19+00:00

This is likely something easy to accomplish, but I’m having difficulty even articulating clearly,

  • 0

This is likely something easy to accomplish, but I’m having difficulty even articulating clearly, leading me to get all sorts of semi-germaine, but not quite what I’m after posts on SO when searching.

I have a resource, we’ll just use User as a simple to discuss use case. I desire SEO friendly URLs, so instead of ~/users/:id, we have ~/users/:name, where the show action on my users controllers is doing a User.find_by_name(:name). Works great.

In various parts of the app, I want to redirect the end user back to my resource. The docs seem to indicate I should do

redirect_to @user, :notice => "your page is now DIAMONDS!"'

The problem here is that this automatically appears to use the :id value of the resource, which isn’t what I’m after. I’m wondering if there’s a way to just define a route in my routes file which is aware of my desire to use the name property–and then just redirect to the generated route_url helper. But I’m at a loss for how to do that.

In the interim, I’m resorting to this:

flash[:notice]    = "Your account is now DIAMONDS.  *fist bump*"
redirect_to :action => :show , :id => @user.name

This is less than ideal to me as it’s a good bit of repeated code (I have lots of UI elements that will be linking back to my resource) and because I can’t seem to figure out how to include the flash as part of the redirect_to method call—every combo of curly bracing w/in the redirect_to that includes a flash bombs on me.

I don’t think it’s germaine to my problem specifically, but I am doing this on Rails 3 in case it does have some implication in terms of options available to me.

Sorry for the noobishness 🙂

  • 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-16T07:39:20+00:00Added an answer on May 16, 2026 at 7:39 am

    Pretty simple to do. The standardish way of doing this is:

    /app/models/user.rb

    def to_param
      "#{id}-#{name}"
    end
    

    That’s nice, and gives you nicer SEO — http://yoursite.com/users/1345-supercool …. You can tweak it a bit to remove the ‘1345’:

    /app/models/user.rb

      # add_column :permalink, :string
      attr_protected :permalink
      before_create :set_permalink
      validates_uniqueness_of :permalink
    
      def set_permalink
        self.permalink = username.parameterize
      end
    
      def to_param
        permalink
      end
    

    This will give you http://yoursite.com/users/supercool and will be a permanent URL, so that if the user changes their username later, the URL will stay the same and keep search engines happy.

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

Sidebar

Related Questions

This is likely going to be an easy answer and I'm just missing something,
I guess this is an odd one, and the answer is most likely it
This is a bit of a long shot, but if anyone can figure it
This is kinda oddball, but I was poking around with the GNU assembler today
This might seem like a stupid question I admit. But I'm in a small
This is a difficult and open-ended question I know, but I thought I'd throw
This is my first post here and I wanted to get some input from
This error just started popping up all over our site. Permission denied to call
This is starting to vex me. I recently decided to clear out my FTP,
This past summer I was developing a basic ASP.NET/SQL Server CRUD app, and unit

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.