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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:38:36+00:00 2026-05-25T18:38:36+00:00

I have a web app made with Ruby On Rails. For now when I

  • 0

I have a web app made with Ruby On Rails. For now when I want to display an object I have to access the following page: http://mywebapp.com/object/1234 with 1234 the id of the object.

I would like to encode that object id and have the following result: http://mywebapp.com/object/5k (it is just an example).

How can it be done?

Many thanks,
Martin

  • 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-25T18:38:36+00:00Added an answer on May 25, 2026 at 6:38 pm

    All these converting methods are reversible, so IMHO if your object has some name or title or whatever, then the best way is adding a slug.
    In such case add a new attribute :slug to your object, let automatically generate it’s value from object name (or something else) on the model:

    class MyObject
    
      validates_format_of :slug, :with => /\A[a-z\-0-9]*\Z/
      before_validation :generate_slug, :on => :create    
    
      def generate_slug
        if self.slug.blank?
          slug = self.name.mb_chars.downcase.normalize(:kd).to_s.gsub(/-/, " ").squeeze(" ")
          slug = slug.gsub(/\s/, "-").gsub(/[^a-z\-0-9]/, "")
    
          current = 1
          self.slug = slug
          while true
            conflicts = MyObject.where("slug = ?", self.slug).count
            if conflicts != 0
              self.slug = "#{slug}-#{current}"
              current += 1
            else
              break
            end
          end
        end
      end
    end
    

    then the URL can be http://mywebapp.com/object/my_object_slug, because in action you find the object via this slug:

    class MyObjectController
    
      def some_action
        my_object = MyObject.find_by_slug(params[:slug])
    
        ...
    
      end
    end
    

    Don’t forget modify routes.rb:

    match "object/:slug", :to => "my_objects#some_action"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made small web-app in jsp with a start page with login and
I've made a small web app using web.py that I now want to put
I have made an app that gets an array of addresses from a web
I have a web app built against asp.net 2.0, but keep getting the following
I have a web app game and while in the game I want to
In the bug fixing of a small ASP.NET/C# web app I have made, I
I have made a web app where I am using a module which redirects
I have a ruby web application and I want to structure the UI layer
I have a web app that users upload files to. I want to authenticate
I have made a web app and we are using imageflow And in the

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.