在我的Character模型中,我添加了:
character.rb
before_save do
self.profile_picture_url = asset_path('icon.png')
end
Run Code Online (Sandbox Code Playgroud)
但是,对于数据库中已存在的所有字符,它们profile_picture_url是nil.因此,我想进入控制台并遍历所有这些并设置它.在控制台我试过:
Character.find_each do |c|
c.profile_picture_url = asset_path('icon.png')
end
Run Code Online (Sandbox Code Playgroud)
但是这给出了错误:
NoMethodError: undefined method `asset_path' for main:Object
Run Code Online (Sandbox Code Playgroud)
我希望我已经充分地传达了我想要实现的目标.我哪里错了?