2

Here is my model:

class User
  def join(race)
    #blah blah blah ....
    UserMailer.delay.join_race(self, race) #I'm stuck here
  end
end

And my UserMailer like this

class UserMailer
  def join_race(user, race)
    #Another blah blah blah, nothing important here
    mail(:to => user.email)
  end
end

Now, whenever I call user.join(race), it shows the error like this:

ArgumentError: wrong number of arguments (2 for 1)
from /home/xxx/.rvm/gems/ruby-1.9.3-p194/gems/arel-3.0.2/lib/arel/expressions.rb:3:in `count'
from /home/xxx/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:224:in `binary?'
from /home/xxx/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:233:in `visit_String'
from /home/xxx/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `accept'
from /home/xxx/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:292:in `block in visit_Hash'
from /home/xxx/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:290:in `each'
 ...

If I convert it to normal function (without the .delay in front of join_race), it works.

I found similar issues but they are all about not calling .all method after using where. I suspect that the self could be the problem but I don't know how to make it work. If any of you have any clue, please share with me.

4

2 回答 2

3

此问题在https://github.com/rails/arel/issues/149中进行了讨论,包括提到 Mailer 和延迟作业,以及相关的https://github.com/rails/rails/issues/9263

包括以下解决方法:

module Arel
  module Nodes
    class SqlLiteral < String
      def encode_with(coder)
        coder['string'] = to_s
      end
      def init_with(coder)
        clear << coder['string']
      end
    end
  end
end
于 2013-07-16T05:38:29.527 回答
0

问题是因为我使用的是 Rails 3.2.12。这个问题似乎只出现在这个版本的 Rails 中。因此,我将我的项目升级到 Rails 3.2.13 并且一切正常。

于 2013-07-16T06:54:35.503 回答