【发布时间】:2016-09-10 01:00:21
【问题描述】:
我正在阅读this question,上面写着电话
something {|i| i.foo }
something(&:foo)
是等价的。
现在我正在尝试根据此模式重构名为 AdminUser 的模型并替换
after_create { |admin| admin.send_reset_password_instructions }
与
after_create(&:send_reset_password_instructions)
,但是当我运行我的迁移时,其中包含行
def migrate(direction)
super
# Create a default user
AdminUser.create!(email: 'a@b.de', password: 'very_clever', password_confirmation: 'very_clever') if direction == :up
end
它给了我错误
ArgumentError: no receiver given
指向AdminUser.create!...这一行。
谁能告诉我这里出了什么问题?
【问题讨论】:
-
我看不出你不能用更短的形式替换
after_create { |admin| admin.send_reset_password_instructions },所以我会在别处寻找问题。你在想,“但在我做出改变之前它就起作用了”,但我会仔细检查你是否做了其他改变,也许是无意的。 -
更好,为什么不直接做
after_create :send_reset_password_instructions
标签: ruby-on-rails ruby ruby-on-rails-4 ruby-2.1