A
A
Adil12013-11-27 23:31:38
Ruby on Rails
Adil1, 2013-11-27 23:31:38

How to make user_helper correctly?

I want to make a helper for avatars, but even it doesn’t work
. In general, what we have:

module UsersHelper
  def avatar_for(user, options = { size: 50 })
    if user.nil? or user.avatar.nil?
      image_tag('/uploads/1.png', :size => 50)
      size = options[:size]
    else
      image_tag(user.avatar.thumb, :size => 52)
      size = options[:size]
    end
  end
end

I insert it into the view
<%= avatar_for @user %>
But it doesn't work, I use carierwave and rmagick for cropping.
Yes, by the way, can anyone come across crop? What do you advise?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jj_killer, 2013-11-27
@Adil1

The task is clear, but it looks like this:

module UsersHelper
  def avatar_for(user, options = { size: 50 })
    if user.try(:avatar).blank?
      image_tag('/uploads/1.png', :size => options[:size])
    else
      image_tag(user.avatar.thumb, :size => options[:size])
    end
  end
end

J
jj_killer, 2013-11-27
@jj_killer

It's not clear what you're doing size = options[:size]here. You need to pass size to image_tag, but in fact your helper just outputs options[:size] instead of image_tag.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question