【发布时间】:2015-06-30 18:05:02
【问题描述】:
我在我的 rails 应用程序中收到以下错误。
错误:
NoMethodError in Statuses#index
显示 C:/Users/Arvind/project/book/app/views/statuses/index.html.erb 其中第 12 行提出:
未定义的方法“头像?”对于 nil:NilClass
Rails.root:C:/Users/Arvind/project/book 应用程序跟踪 |框架跟踪 |全程跟踪
app/helpers/applicationhelper.rb:28:in avatar_profile_link' app/views/statuses/index.html.erb:12:inblock in _app_views_statuses_index_html_erb__844883668_70166988' app/views/statuses/index.html.erb:9:in _app_views_statuses_index_html_erb___8448 'app/controllers/statuses_controller.rb:13:inindex'
我的用户.rb
attr_accessible :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :profile_name, :full_name, :avatar
has_attached_file :avatar, style: { large: "800x800>", medium: "300x200>", small: "260x180>", thumb: "80x80#" }
def self.get_gravatars
all.each do |user|
if !user.avatar?
user.avatar = URI.parse(user.gravatar_url)
user.save
print "."
end
end
end
我的 application_helper.rb
def avatar_profile_link(user, image_options={}, html_options={})
avatar_url = 用户头像? ? user.avatar.url(:thumb) : 无
link_to(image_tag(avatar_url, image_options), profile_path(user.profile_name), html_options)
结束
我的 lib/task/gravatars,rake
desc "Import avatars from user's gravatar url"
task :import_avatars => :environment do
puts "Importing avatars from gravatar"
User.get_gravatars
puts "Avatars updated."
end
我已将我的头像更新为 gravatar
$rake import avatar
将头像导入到gravatar
.....头像已更新。
我的 git 存储库位于:https://github.com/sarahgupta022/book.git
谢谢!
【问题讨论】:
标签: ruby-on-rails ruby