I am receiving the following errors in my rails app.
Error:
NoMethodError in Statuses#index
Showing C:/Users/Arvind/project/book/app/views/statuses/index.html.erb where line #12 raised:
undefined method `avatar?' for nil:NilClass
Rails.root: C:/Users/Arvind/project/book Application Trace | Framework Trace | Full Trace
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___844883668_70166988' app/controllers/statuses_controller.rb:13:inindex'
My user.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
My application_helper.rb
def avatar_profile_link(user, image_options={}, html_options={})
avatar_url = user.avatar? ? user.avatar.url(:thumb) : nil
link_to(image_tag(avatar_url, image_options), profile_path(user.profile_name), html_options)
end
My 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
I updated My avatar to gravatar
$rake import avatar
Importing avatar to gravatar
.....Avatar updated.
My git repository is at: https://github.com/sarahgupta022/book.git
Thank You!