Thor::Group:Class 的未定义方法“find_each”
undefined method `find_each' for Thor::Group:Class
我编写了一个 Thor 任务,该任务应该遍历所有利用 find_each
的用户。但我收到此错误消息:
Thor::Group:Class`
的未定义方法 find_each
为什么这里 find_each 不可用? 运行 User.find_each { |u| puts u.name }
在 rails 控制台中工作。
class CloudImages < Thor
require "./config/environment.rb"
desc "save_user_avatar_urls", "Save existing AWS user avatars"
def save_user_avatar_urls
User.find_each do |user|
next if user.avatar_url.blank?
path = URI(user.avatar_url).path
image_url = $DOMAIN + path
user.update_attribute(:aws_avatar_url, image_url)
end
end
end
将User
更改为::User
class CloudImages < Thor
require "./config/environment.rb"
desc "save_user_avatar_urls", "Save existing AWS user avatars"
def save_user_avatar_urls
::User.find_each do |user|
next if user.avatar_url.blank?
# ...
end
end
end
我编写了一个 Thor 任务,该任务应该遍历所有利用 find_each
的用户。但我收到此错误消息:
Thor::Group:Class`
find_each
为什么这里 find_each 不可用? 运行 User.find_each { |u| puts u.name }
在 rails 控制台中工作。
class CloudImages < Thor
require "./config/environment.rb"
desc "save_user_avatar_urls", "Save existing AWS user avatars"
def save_user_avatar_urls
User.find_each do |user|
next if user.avatar_url.blank?
path = URI(user.avatar_url).path
image_url = $DOMAIN + path
user.update_attribute(:aws_avatar_url, image_url)
end
end
end
将User
更改为::User
class CloudImages < Thor
require "./config/environment.rb"
desc "save_user_avatar_urls", "Save existing AWS user avatars"
def save_user_avatar_urls
::User.find_each do |user|
next if user.avatar_url.blank?
# ...
end
end
end