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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:01:46+00:00 2026-06-12T07:01:46+00:00

I am using acts-as-taggable-on for a Rails application and every time I create a

  • 0

I am using acts-as-taggable-on for a Rails application and every time I create a new Photo (for example) I get duplicate rows in the ‘taggings’ table.

My model classes look something like:

class User < ActiveRecord::Base
  acts_as_tagger
  ...
end

and

class Photo < ActiveRecord::Base
   acts_as_taggable_on :tags
   ...
end

and in the create action of my photos_controller

def create
  @user = current_user
  ... 
  @user.tag(@photo, :with => params[:photo][:tag_list], :on => :tags)
  ...
end

The strange thing is that I get duplicate rows in the ‘taggings’ table where the first row has ‘tagger_id’ and ‘tagger_type’ set to NULL while the duplicate row has the correct values.

my Gemfile looks like this

gem 'rails', '3.2.8'
gem 'acts-as-taggable-on', '~> 2.3.1'

Has anyone seen this behavior before? Is it a configuration problem on my end?

Update:
Looking at the console I can clearly see two transactions being performed and in the first one there is this:

SQL (0.6ms)  INSERT INTO "taggings" ("context", "created_at", "tag_id", 
"taggable_id", "taggable_type", "tagger_id", "tagger_type") VALUES (?, ?, ?, ?, ?, ?, ?)
[["context", "tags"], ["created_at", Thu, 27 Sep 2012 21:49:22 UTC +00:00], ["tag_id",
 12], ["taggable_id", 10], ["taggable_type", "Photo"], 
["tagger_id", nil], ["tagger_type", nil]]

and it is clear that tagger_id is set to null as well as tagger_type.

Here is a full console output, I have separated the lines to help read it. You will notice two separate transactions and in the first one there is the insert with NULL values while at the end of the second one you will see the correct one.

Started POST “/photo” for 127.0.0.1 at 2012-09-28 07:39:58 +0200
Processing by PhotoController#create as HTML
Parameters: {“utf8″=>”✓”, “authenticity_token”=>”IOmnfDpU7V7vYw3h6RXXzXPsXf/B0fcVihXhb+S8JHU=”, “photo”=>{“url”=>”www.another.com/photo.jpg”, “title”=>”Another”, “tag_list”=>”a_tag”, “description”=>””, “private”=>”0”}, “commit”=>”Add Photo”}
Redirected to http://www.somedomain.com:3000/users/christiangiacomi

Completed 302 Found in 414ms (ActiveRecord: 20.5ms)

User Load (0.3ms) SELECT “users”.* FROM “users” WHERE “users”.”username” = ‘christiangiacomi’ LIMIT 1
ActsAsTaggableOn::Tag Load (0.2ms) SELECT “tags”.* FROM “tags” INNER JOIN “taggings” ON “tags”.”id” = “taggings”.”tag_id” WHERE “taggings”.”taggable_id” IS NULL AND “taggings”.”taggable_type” = ‘Photo’ AND (taggings.context = ‘tags’ AND taggings.tagger_id IS NULL)

(0.1ms) begin transaction

SQL (6.2ms) INSERT INTO “photos” (“created_at”, “description”, “favorite”, “private”, “title”, “updated_at”, “url”, “user_id”) VALUES (?, ?, ?, ?, ?, ?, ?, ?) [[“created_at”, Fri, 28 Sep 2012 05:39:59 UTC +00:00], [“description”, “”], [“favorite”, false], [“private”, false], [“title”, “Another”], [“updated_at”, Fri, 28 Sep 2012 05:39:59 UTC +00:00], [“url”, “http://www.another.com/photo.jpg”%5D, [“user_id”, 1]]

ActsAsTaggableOn::Tag Load (3.2ms) SELECT “tags”.* FROM “tags” WHERE (lower(name) = ‘a_tag’)
ActsAsTaggableOn::Tag Exists (0.1ms) SELECT 1 AS one FROM “tags” WHERE “tags”.”name” = ‘a_tag’ LIMIT 1

SQL (0.2ms) INSERT INTO “tags” (“name”) VALUES (?) [[“name”, “a_tag”]]

ActsAsTaggableOn::Tag Load (0.1ms) SELECT “tags”.* FROM “tags” INNER JOIN “taggings” ON “tags”.”id” = “taggings”.”tag_id” WHERE “taggings”.”taggable_id” = 13 AND “taggings”.”taggable_type” = ‘Photo’ AND (taggings.context = ‘tags’ AND taggings.tagger_id IS NULL)

ActsAsTaggableOn::Tagging Exists (0.2ms) SELECT 1 AS one FROM “taggings” WHERE (“taggings”.”tag_id” = 16 AND “taggings”.”taggable_type” = ‘Photo’ AND “taggings”.”taggable_id” = 13 AND “taggings”.”context” = ‘tags’ AND “taggings”.”tagger_id” IS NULL AND “taggings”.”tagger_type” IS NULL) LIMIT 1

SQL (0.7ms) INSERT INTO “taggings” (“context”, “created_at”, “tag_id”, “taggable_id”, “taggable_type”, “tagger_id”, “tagger_type”) VALUES (?, ?, ?, ?, ?, ?, ?) [[“context”, “tags”], [“created_at”, Fri, 28 Sep 2012 05:39:59 UTC +00:00], [“tag_id”, 16], [“taggable_id”, 13], [“taggable_type”, “Photo”], [“tagger_id”, nil], [“tagger_type”, nil]]

(4.1ms) commit transaction

(0.1ms) begin transaction

ActsAsTaggableOn::Tag Load (0.2ms) SELECT “tags”.* FROM “tags” WHERE (lower(name) = ‘a_tag’)

ActsAsTaggableOn::Tag Load (0.2ms) SELECT “tags”.* FROM “tags” INNER JOIN “taggings” ON “tags”.”id” = “taggings”.”tag_id” WHERE “taggings”.”taggable_id” = 13 AND “taggings”.”taggable_type” = ‘Photo’ AND (taggings.context = ‘tags’ AND taggings.tagger_id IS NULL)

CACHE (0.0ms) SELECT “tags”.* FROM “tags” WHERE (lower(name) = ‘a_tag’)

ActsAsTaggableOn::Tag Load (0.2ms) SELECT “tags”.* FROM “tags” INNER JOIN “taggings” ON “tags”.”id” = “taggings”.”tag_id” WHERE “taggings”.”taggable_id” = 13 AND “taggings”.”taggable_type” = ‘Photo’ AND (taggings.context = ‘tags’ AND
taggings.tagger_id = 1 AND
taggings.tagger_type = ‘User’)

ActsAsTaggableOn::Tagging Exists (0.4ms) SELECT 1 AS one FROM “taggings” WHERE (“taggings”.”tag_id” = 16 AND “taggings”.”taggable_type” = ‘Photo’ AND “taggings”.”taggable_id” = 13 AND “taggings”.”context” = ‘tags’ AND “taggings”.”tagger_id” = 1 AND “taggings”.”tagger_type” = ‘User’) LIMIT 1

SQL (0.5ms) INSERT INTO “taggings” (“context”, “created_at”, “tag_id”, “taggable_id”, “taggable_type”, “tagger_id”, “tagger_type”) VALUES (?, ?, ?, ?, ?, ?, ?) [[“context”, “tags”], [“created_at”, Fri, 28 Sep 2012 05:39:59 UTC +00:00], [“tag_id”, 16], [“taggable_id”, 13], [“taggable_type”, “Photo”], [“tagger_id”, 1], [“tagger_type”, “User”]]

(2.4ms) commit transaction

  • 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-06-12T07:01:48+00:00Added an answer on June 12, 2026 at 7:01 am

    Ok, this is really strange, but I have figured out how to avoid the problem.

    The fist thing I did was to create a spike solution to test acts_as_taggable_on and that seemed to work. It consisted of two model classes and that’s it… and it worked when I tested it via the rails console.

    So I added a form like I had in my rails app and the tested it again…

    I had a form that was something like this:

       <div>
          <%= form_for @photo, :html => { :class => "dialog" } do |f| %>
    
          ...
    
          <%= f.label :title%>
          <%= f.text_field :title, :class => "wide" %>
    
          <%= f.label 'Tags' %>
          <%= f.text_field :tag_list, :value => @tags %>
    
          ...
    
          <%= f.submit button_text(@photo), :class => "btn btn-large btn-primary" %>
          <%= f.submit "Cancel", :class => "btn btn-large"  %>
       </div>
    

    And when I implemented this and tested it I got a ‘Cannot mass assign :tag_list’

    I read about the changed in Rails 3.2.3 regarding mass assignment and decided not to compromise security.

    So I added to my Photo model class

     attr_accessible :tag_list
    

    That solved the error BUT when I tested it I found that the duplicate rows where NOW appearing! So now the bug is reproducible!!

    I solved it by changing the form so that I don’t bind the form to the Photo model object.

    Like so:

    <div>
       <%= form_tag({:controller => "photos", :action => "create"}, :method => "post", :class => "dialog") do %>
    
       ...
    
       <%= label_tag :title, 'Title'%>
       <%= text_field_tag :title, nil, :class => "wide" %>
    
       <%= label_tag :tag_list, 'Tags'%>
       <%= text_field_tag :tag_list, nil, :class => "wide" %>
    
       ...
    
       <%= submit_tag('Add', :class => "btn btn-large btn-primary") %>
       <%= submit_tag("Cancel", :class => "btn btn-large")  %>
    </div>
    

    I also removed the attr_accessible :tag_list and modified the controller to accept the different values from the form.

    @photo = current_user.photos.build(:title => params[:title],
                                       ...
                                       )
    @user.tag(@photo, :with => params[:tag_list], :on => :tags)
    

    And that solved the problem!

    I will now try to look into exactly why this is happening! 🙂

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

Sidebar

Related Questions

Hi I'm using the rails plugin acts-as-taggable-on and I'm trying to find the top
Am using below specified gem acts-as-taggable-on(2.2.2) will_paginate(3.0.2) rails(3.0.3) ruby 1.8.7 i tried to use
I'm using acts-as-taggable-on in my application and I want to be able to use
I am using acts_as_taggable to create a tag cloud for my application. I have
I am using the old auto_complete plugin in conjunction with the acts as taggable
I am using acts-as-taggable on. Two models: User and Posts. Posts belongs_to :user User
I'm creating a Related content area on a website and using the acts-as-taggable-on gem
I'm trying to get tags working in my rails application and want to use
I'm trying to install acts_as_ferret in windows7.But am getting an error Using acts-as-taggable-on (2.1.1)
I'm using acts_as_taggable_on in rails and I'm trying to get a listing of all

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.