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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:37:18+00:00 2026-05-23T23:37:18+00:00

I’m using acts_as_taggable_on in an app and I would like to extract the tag

  • 0

I’m using acts_as_taggable_on in an app and I would like to extract the tag ids (not the tag names) that a post has been tagged with.

My app has a posts controller, and in ruby console I can do:

 >> post = Post.find(1)
   => #<Post id: 1, content: "Aliquam cupiditate ea deserunt et id placeat molest...", user_id: 1, created_at: "2011-07-06 19:29:44", updated_at: "2011-07-06 19:29:44">
 >> tags = post.tag_counts_on("topics")
   => [#<ActsAsTaggableOn::Tag id: 1, name: "Politics">, #<ActsAsTaggableOn::Tag id: 2, name: "Economics">] 

Here I have shown that the post is tagged with topic ids “Politics” and “Economics”. My problem is, I want to save this information on a cookie for use later. But I can’t store a hash on a cookie, I can only store strings of information. If I do:

 session[:store_name] = tags.join(",")

And then later:

 tags = session[:store_name].split(",")

I will get a hash:

 ["Politics", "Economics", ...]

But this hash doesn’t have a record of the tag_id for each topic tag. Is there any way to pull the ids out at some point and save them for later with the acts_as_taggable_on output? Or some suggestions on how to preserve the output from acts_as_taggable_on for later use?

  • 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-23T23:37:19+00:00Added an answer on May 23, 2026 at 11:37 pm

    If you need the id’s, just do

    tags.map(&:id).join(",")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I would like to run a str_replace or preg_replace which looks for certain words
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I am using Paperclip to handle profile photo uploads in my app. They upload

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.