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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:15:42+00:00 2026-05-22T14:15:42+00:00

I would like to create url slugs for tags managed by the acts_as_taggable_on gem.

  • 0

I would like to create url slugs for tags managed by the acts_as_taggable_on gem. For instance instead of urls like http://myapp.com/tags/5, I would like to have http://myapp.com/tags/my-tag (where ‘my tag’ is the tag’s unique name).

In models that I create myself I usually do this by overriding the model’s to_param method, and creating a “slug” field in the model to save the result of the new to_param method. I tried doing this with the Tag model of ActsAsTaggableOn, but it is not working.

I can otherwise override things in the tag.rb class of ActsAsTaggableOn as follows:

# Overwrite tag class
ActsAsTaggableOn::Tag.class_eval do
  def name
    n = read_attribute(:name).split
    n.each {|word| word.capitalize!}.join(" ")
  end      
end

However, if I try to override the to_param method in that same block with a method definition like:

def to_param
  name.parameterize
end

Rails still generates and responds to routes with integer IDs rather than the parameterized name. In fact in the console if I try something like

ActsAsTaggableOn::Tag.find(1).to_param

The integer ID is returned, rather than the result of the overridden to_param method.

I’d rather not fork the gem and customize it if there is any way I can do it with my own application code. Thanks.

  • 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-22T14:15:42+00:00Added an answer on May 22, 2026 at 2:15 pm

    I’m using the friendly_id ( https://github.com/norman/friendly_id ) gem to manage slugs. My method to create slugs for my tags is similar to yours, but a lit bit simpler.

    I’ve just created the initializer act_as_taggable_on.rb with the following code:

    # act_as_taggable_on.rb
    ActsAsTaggableOn::Tag.class_eval do
      has_friendly_id :name,
                      :use_slug => true,
                      :approximate_ascii => true,
                      :reserved_words => ['show', 'edit', 'create', 'update', 'destroy']
    end
    

    And then:

    @user = User.new :name => "Jamie Forrest"
    @user.tag_list = "This is awesome!, I'm a ruby programmer"
    @user.save
    

    And voilá:

    ActsAsTaggableOn::Tag.find('this-is-awesome')    #=> #<Tag id: 1, name: "This is awesome!">
    ActsAsTaggableOn::Tag.find('im-a-ruby-programmer')    #=> #<Tag id: 2, name: "I'm a ruby programmer">
    

    Hope this help…

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

Sidebar

Related Questions

YouTube has URL's like these: http://www.youtube.com/watch?v=zKqeCtjFGFc When I create a PHP page mine would
I would like to create a url just like followings : http://localhost/news/announcement/index http://localhost/news/health/index http://localhost/news/policy/index
I would like to create a single URL that returns one image when loaded
I would like create URL rewrite rule that will set default document for my
In SSRS 2008 I would like to create a relative path URL. Long story
I would like to create screenshots of web pages from a given URL. While
I would like to create a WCF that can be invoked via a HTTP
I would like to create URL's that, if the user clicks, log them in
I would like to create custom slugs for pages in my CMS, so users
I would like to create an android application which views an existing web URL,

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.