ArgumentError:使用afer_save时参数数目错误(1代表0) ArgumentError:参数数目错误(1代表0) from/Users/Castillo/Desktop/gainer/app/models/status.rb:13:in“update\u remainment\u” from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:507:in'block in callback' from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:504:in'each' from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:504:in'callback' from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:352:“添加到目标” from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:495:in“concat\u记录中的块” from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:493:in'each' from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:493:in'concat\u records' from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:134:in'block in concat' from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:149:在“事务中的块”中 来自/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/connection\u adapters/abstract/database\u语句。rb:192:在“事务”中 from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active_record/transactions.rb:208:in“transaction” from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:148:在“事务”中 from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:134:in'concat' 从/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u proxy.rb:116:在“

ArgumentError:使用afer_save时参数数目错误(1代表0) ArgumentError:参数数目错误(1代表0) from/Users/Castillo/Desktop/gainer/app/models/status.rb:13:in“update\u remainment\u” from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:507:in'block in callback' from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:504:in'each' from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:504:in'callback' from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:352:“添加到目标” from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:495:in“concat\u记录中的块” from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:493:in'each' from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:493:in'concat\u records' from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:134:in'block in concat' from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:149:在“事务中的块”中 来自/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/connection\u adapters/abstract/database\u语句。rb:192:在“事务”中 from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active_record/transactions.rb:208:in“transaction” from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:148:在“事务”中 from/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u association.rb:134:in'concat' 从/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active\u record/associations/collection\u proxy.rb:116:在“,ruby,ruby-on-rails-3,rails-activerecord,has-many,Ruby,Ruby On Rails 3,Rails Activerecord,Has Many,中,如果您查看文档部分,您将看到以下示例: class Meal < ActiveRecord::Base attr_accessible :name, :description, :clean_up, :homemade, :prep_time, :user_id, :status_id belongs_to :user belongs_to :status has_many :ingredient_meals has_many :ingredients,

中,如果您查看文档部分,您将看到以下示例:

class Meal < ActiveRecord::Base
  attr_accessible :name, :description, :clean_up, :homemade, :prep_time, :user_id, :status_id

  belongs_to :user
  belongs_to :status
  has_many   :ingredient_meals
  has_many   :ingredients, :through => :ingredient_meals

end
这并不是你与
之间有多少关系,但它已经足够紧密了。如果查看
evaluate\u velocity
方法,您将看到有问题的
开发人员
通过
:after\u add
回调作为参数传递。当您的
update\u remaining\u
不需要任何参数并且与示例所建议的情况相匹配时,将使用一个参数调用您的
update\u remaining\u

试试这个:

class Project
  has_and_belongs_to_many :developers, after_add: :evaluate_velocity

  def evaluate_velocity(developer)
    ...
  end
end
class Status < ActiveRecord::Base
  attr_accessible :remaining_calories, :remaining_carbs, :remaining_protein, :weight, :user_id

  belongs_to :user
  has_many :meals, after_add: :update_remaining_nutrients

  after_save :update_users_weight , :if => Proc.new {|a| a.weight_changed?}

  def update_users_weight
    self.user.weight.update_attributes(weight: self.weight)
  end

  def update_remaining_nutrients
    puts "It Works!!!!!"
  end

end
class Meal < ActiveRecord::Base
  attr_accessible :name, :description, :clean_up, :homemade, :prep_time, :user_id, :status_id

  belongs_to :user
  belongs_to :status
  has_many   :ingredient_meals
  has_many   :ingredients, :through => :ingredient_meals

end
class Project
  has_and_belongs_to_many :developers, after_add: :evaluate_velocity

  def evaluate_velocity(developer)
    ...
  end
end
def update_remaining_nutrients(meal)
  # Do interesting things with `meal` in here...
end