【发布时间】:2017-12-26 21:30:52
【问题描述】:
在我的Character 模型中我添加了:
character.rb
before_save do
self.profile_picture_url = asset_path('icon.png')
end
但是,对于数据库中已经存在的所有字符,它们的profile_picture_url 是nil。因此,我想进入控制台并遍历所有这些并设置它。在我尝试过的控制台中:
Character.find_each do |c|
c.profile_picture_url = asset_path('icon.png')
end
但这给出了错误:
NoMethodError: undefined method `asset_path' for main:Object
我希望我已经充分传达了我想要实现的目标。我哪里错了?
【问题讨论】:
标签: ruby-on-rails ruby rails-console