Repository: mbleigh/acts-as-taggable-on

Issue #742: ActsAsTaggableOn::Tagging Exists ROLLBACK when saving tag_list - Rails 5.0.0.beta3
Created: 2016-03-29T06:20:12Z
Hoping someone may know what is happening with this rollback occuring when trying to save the tag_list.
gem 'rails', '>= 5.0.0.beta3', '< 5.1'
gem 'acts-as-taggable-on', '~> 3.4'
I have a model named cast that has acts_as_taggable # Alias for acts_as_taggable_on :tags specified in the cast.rb file. The model saves fine and only fails when I try and save the tag_list field.
This is in the controller in the private area.
def cast_params
  params.require(:cast).permit(
    :name,
    :description,
    :provider_name,
    :provider_url_id,
    :length,
    :provider_url_id,
    :pro_episode,
    :content,
    :tag_list
  )
end
Here is an example of the failure occuring from rails console. I don't know if this is a rails beta3 issue or something I have done wrong. It is a new application and I don't think I have done anything outside of the github readme file.
irb(main):001:0> c = Cast.new

DEPRECATION WARNING: Time columns will become time zone aware in Rails 5.1. This
still causes `String`s to be parsed as if they were in `Time.zone`,
and `Time`s to be converted to `Time.zone`.

To keep the old behavior, you must add the following to your initializer:

    config.active_record.time_zone_aware_types = [:datetime]

To silence this deprecation warning, add the following:

    config.active_record.time_zone_aware_types << :time
 (called from irb_binding at (irb):1)

=> #<Cast id: nil, name: nil, description: nil, created_at: nil, updated_at: nil, provider_name: nil, provider_url_id: nil, length: nil, pro_episode: nil, content: nil>
irb(main):002:0> c.tag_list.add("test")
=> ["test"]
irb(main):003:0> c.save
   (0.2ms)  BEGIN
  SQL (0.5ms)  INSERT INTO "casts" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id"  [["created_at", 2016-03-29 06:10:31 UTC], ["updated_at", 2016-03-29 06:10:31 UTC]]
  ActsAsTaggableOn::Tag Load (0.8ms)  SELECT "tags".* FROM "tags" WHERE (LOWER(name) = LOWER('test'))
  ActsAsTaggableOn::Tag Exists (0.6ms)  SELECT  1 AS one FROM "tags" WHERE "tags"."name" = $1 LIMIT $2  [["name", "test"], ["LIMIT", 1]]
  SQL (0.4ms)  INSERT INTO "tags" ("name") VALUES ($1) RETURNING "id"  [["name", "test"]]
  ActsAsTaggableOn::Tag Load (1.6ms)  SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL)  [["taggable_id", 12], ["taggable_type", "Cast"]]
  ActsAsTaggableOn::Tag Load (0.2ms)  SELECT  "tags".* FROM "tags" WHERE "tags"."id" = $1 LIMIT $2  [["id", 35], ["LIMIT", 1]]
  ActsAsTaggableOn::Tagging Exists (0.5ms)  SELECT  1 AS one FROM "taggings" WHERE "taggings"."tag_id" = $1 AND "taggings"."taggable_type" = $2 AND "taggings"."taggable_id" = $3 AND "taggings"."context" = $4 AND "taggings"."tagger_id" IS NULL AND "taggings"."tagger_type" IS NULL LIMIT $5  [["tag_id", 35], ["taggable_type", "Cast"], ["taggable_id", 12], ["context", "tags"], ["LIMIT", 1]]
   (0.4ms)  ROLLBACK
=> false

Duplicate issue #762: Rails 5 issue: acts-as-taggable-on 3.5.0 has a dependency on activerecord < 5
Created: 2016-07-01T17:08:53Z
I was trying to upgrade an application to Rails 5, and after deleting my Gemfile.lock and re-running bundle install, I noticed that the dependency resolution yielded acts-as-taggable-on 2.1.1 instead of 3.5.0 (which I assume is the version that should have actual support for Rails 5).
Bundler could not find compatible versions for gem "activerecord":
  In snapshot (Gemfile.lock):
    activerecord (= 5.0.0)

  In Gemfile:
    acts-as-taggable-on (~> 3.5.0) was resolved to 3.5.0, which depends on
      activerecord (< 5, >= 3.2)

    rails (~> 5.0.0) was resolved to 5.0.0, which depends on
      activerecord (= 5.0.0)

How do I get this gem to work with Rails 5?
Bundler::GemRequireError: There was an error while trying to load the gem 'acts-as-taggable-on'.
Gem Load Error is: undefined method `attr_accessible' for #<Class:0x007fab83a14b28>
Did you mean?  attr_accessor
Backtrace for gem load error is:
/Users/tirdad/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0/lib/active_record/dynamic_matchers.rb:21:in `method_missing'
/Users/tirdad/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/acts-as-taggable-on-2.1.1/lib/acts_as_taggable_on/tag.rb:6:in `<class:Tag>'
/Users/tirdad/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/acts-as-taggable-on-2.1.1/lib/acts_as_taggable_on/tag.rb:2:in `<module:ActsAsTaggableOn>'
/Users/tirdad/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/acts-as-taggable-on-2.1.1/lib/acts_as_taggable_on/tag.rb:1:in `<top (required)>'
/Users/tirdad/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'

Closing comment (2016-07-04T17:53:16Z): So that helped get past the initial hurdle, and I ran the new migration it mentioned to add indexes.
Now I can't seem to record new items that have tags as it results in a ROLLBACK:
Started POST "/products" for 127.0.0.1 at 2016-07-04 13:45:25 -0400
Processing by ReleasesController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"5yYz3WHePpzitycC9GKPt0CEZ0LzTPK4JwEl52prPmtFcrSFTqr36bw5Jtj80gX4GqEd/ZNC5wTMi61ZKziP4g==", "release"=>{"artist"=>"Test 1", "title"=>"Test 2", "label"=>"Test 3", "price"=>"12", "format"=>"CD", "details"=>"", "cat_id"=>"", "stock"=>"0", "teaser"=>"", "visible"=>"1", "body"=>"", "release_date"=>"", "soundcloud"=>"", "delete_image"=>"0", "audio"=>"", "genre_list"=>"genre1, genre2", "status_list"=>""}, "redirect"=>"", "commit"=>"Create Release"}
   (0.2ms)  BEGIN
  SQL (0.3ms)  INSERT INTO `releases` (`artist`, `title`, `label`, `teaser`, `body`, `price`, `format`, `details`, `cat_id`, `audio`, `created_at`, `updated_at`, `soundcloud`, `visible`) VALUES ('Test 1', 'Test 2', 'Test 3', '', '', 12.0, 'CD', '', '', '', '2016-07-04 17:45:25', '2016-07-04 17:45:25', '', 1)
  ActsAsTaggableOn::Tag Load (0.6ms)  SELECT `tags`.* FROM `tags` WHERE (LOWER(name) = LOWER('genre1') OR LOWER(name) = LOWER('genre2'))
  ActsAsTaggableOn::Tag Exists (0.3ms)  SELECT  1 AS one FROM `tags` WHERE `tags`.`name` = 'genre1' LIMIT 1
  SQL (0.3ms)  INSERT INTO `tags` (`name`) VALUES ('genre1')
  ActsAsTaggableOn::Tag Exists (0.3ms)  SELECT  1 AS one FROM `tags` WHERE `tags`.`name` = 'genre2' LIMIT 1
  SQL (0.3ms)  INSERT INTO `tags` (`name`) VALUES ('genre2')
  ActsAsTaggableOn::Tag Load (0.4ms)  SELECT `tags`.* FROM `tags` INNER JOIN `taggings` ON `tags`.`id` = `taggings`.`tag_id` WHERE `taggings`.`taggable_id` = 853 AND `taggings`.`taggable_type` = 'Release' AND (taggings.context = 'genres' AND taggings.tagger_id IS NULL)
  ActsAsTaggableOn::Tag Load (0.3ms)  SELECT  `tags`.* FROM `tags` WHERE `tags`.`id` = 72 LIMIT 1
  ActsAsTaggableOn::Tagging Exists (0.4ms)  SELECT  1 AS one FROM `taggings` WHERE `taggings`.`tag_id` = 72 AND `taggings`.`taggable_type` = 'Release' AND `taggings`.`taggable_id` = 853 AND `taggings`.`context` = 'genres' AND `taggings`.`tagger_id` IS NULL AND `taggings`.`tagger_type` IS NULL LIMIT 1
   (0.6ms)  ROLLBACK

Not using tags or updating an already tagged item without changing the tags works fine.
EDIT: it seems this other issue has been reported in #742