Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError (undefined method `tag=' for #<Hash:0x64c1ac0>) #435

Closed
indiepopart opened this issue Sep 29, 2012 · 9 comments
Closed

NoMethodError (undefined method `tag=' for #<Hash:0x64c1ac0>) #435

indiepopart opened this issue Sep 29, 2012 · 9 comments

Comments

@indiepopart
Copy link

Hi!

I'm trying to send a delayed email:

UserMailer.delay.gift_confirmed_email(gift)

And I get NoMethodError (undefined method `tag=' for #Hash:0x64c1ac0)

In environment.rb I have:

require 'yaml'
YAML::ENGINE.yamler = 'syck'

Gems included by the bundle:

  • acl9 (0.12.0)
  • actionmailer (3.2.8)
  • actionpack (3.2.8)
  • activemodel (3.2.8)
  • activerecord (3.2.8)
  • activeresource (3.2.8)
  • activesupport (3.2.8)
  • arel (3.0.2)
  • authlogic (3.1.3)
  • builder (3.0.3)
  • bundler (1.1.4)
  • cocaine (0.3.2)
  • coffee-rails (3.2.2)
  • coffee-script (2.2.0)
  • coffee-script-source (1.3.3)
  • columnize (0.3.6)
  • debugger (1.2.0)
  • debugger-linecache (1.1.2)
  • debugger-ruby_core_source (1.1.3)
  • delayed_job (3.0.3)
  • delayed_job_active_record (0.3.2)
  • erubis (2.7.0)
  • execjs (1.4.0)
  • gdata_19 (1.1.5)
  • hike (1.2.1)
  • i18n (0.6.1)
  • journey (1.0.4)
  • jquery-rails (2.1.3)
  • json (1.7.5)
  • mail (2.4.4)
  • metaclass (0.0.1)
  • mime-types (1.19)
  • mocha (0.12.6)
  • multi_json (1.3.6)
  • mysql2 (0.3.11)
  • nested_form (0.2.3)
  • nifty-generators (0.4.6)
  • paperclip (3.2.0)
  • pg (0.14.0)
  • polyglot (0.3.3)
  • rack (1.4.1)
  • rack-cache (1.2)
  • rack-ssl (1.3.2)
  • rack-test (0.6.2)
  • rails (3.2.8)
  • rails3-generators (0.17.6)
  • railties (3.2.8)
  • rake (0.9.2.2)
  • rdoc (3.12)
  • remotipart (1.0.2)
  • ruby-mysql (2.9.10)
  • rufus-scheduler (2.0.17)
  • sass (3.2.1)
  • sass-rails (3.2.5)
  • sprockets (2.1.3)
  • sqlite3 (1.3.6)
  • thor (0.16.0)
  • tilt (1.3.3)
  • transitions (0.1.1)
  • treetop (1.4.10)
  • tzinfo (0.3.33)
  • uglifier (1.3.0)
  • wicked (0.2.0)
  • will_paginate (3.0.3)

ruby 1.9.3p194 (2012-04-20) [i386-mingw32]

I will appreciate any advice.
Thank you!

@wrodenbusch
Copy link

+1

@albus522
Copy link
Member

Move

require 'yaml'
YAML::ENGINE.yamler = 'syck'

to config/application.rb after

require File.expand_path('../boot', __FILE__)

and before

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end

@constantm
Copy link

@albus522's solution worked for me, thanks!

@hrdwdmrbl
Copy link

Okay, this solves the problem. Thank you!

But, could you please explain why this problem occurs? I'm interested because of another issue we had with YaML de-serialization once.

@albus522
Copy link
Member

When you require yaml before boot, bundler is not setup yet and weird things happen.

@joker-777
Copy link

We are having the same error but in conjunction with IdentityCache https://github.com/Shopify/identity_cache
Internally it uses

record = <a model object>
coder = { :class => record.class }
record.encode_with(coder)

You overwrite encode_with with

def encode_with_override(coder)
  encode_with_without_override(coder)
  coder.tag = "!ruby/ActiveRecord:#{self.class.name}"
end

but the coder is a Hash object, with doesn't have a tag attribute. What do you expect to be a coder? It obviously also breaks with other gems.

@fffanatics
Copy link

+1, we're seeing the same problem that @joker-777 is seeing. Any thoughts on how to fix?

Edit: I added

require 'yaml'
YAML::ENGINE.yamler = 'syck'

To my application.rb as suggested above. This was able to get normal fetch operations working but only if I didn't have any assocaitions (ie: cache_has_many, etc). If I add those, it fails every time with:

TypeError: can't convert Hash into String
from ~/.rvm/gems/ruby-1.9.3-p484/gems/json-1.8.1/lib/json/common.rb:155:in `initialize'

Thoughts?

@berk
Copy link

berk commented Dec 4, 2013

@joker-777 i am doing the same thing, identity_cache + delayed_job and they don't seem to like each other in the same app. what did you end up doing?

@DavidBennettPIO
Copy link

I got identity_cache in ruby 2.1.2 working by override the override and checking for a Hash.

ActiveRecord::Base.class_eval do
  def encode_with_override_override(coder)
    encode_with_without_override(coder)
    coder.tag = "!ruby/ActiveRecord:#{self.class.name}" unless coder.is_a? ::Hash
  end
  alias_method :encode_with, :encode_with_override_override
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants