Using asset_path in Rails console

Viewed 6206

In my Character model I have added:

character.rb

before_save do
  self.profile_picture_url = asset_path('icon.png')
end

However, for all the Characters that already exist in the database, their profile_picture_url is nil. I therefore want to enter the console and iterate through all of them and set it. In the console I tried:

Character.find_each do |c|
  c.profile_picture_url = asset_path('icon.png')
end

But this gives the error:

NoMethodError: undefined method `asset_path' for main:Object

I hope I have adequately communicated what I am trying to achieve. Where am I going wrong?

2 Answers
Related