Search code examples
htmlruby-on-railsrubygravatar

rails3 helper method return size


I have a gravatar method in the User_helper of a Rails3 application. The code is below:

module UsersHelper
  def gravatar_for(user, options = {:size => 50})
    gravatar_image_tag(user.email.downcase, :alt => user.name,
                                            :class => "gravatar",
                                            :gravatar => options)
  end
end

Currently this method sets the default size as 50px yet this is changed in some implementations throughout the app. I want the gravatar to become part of the "round" class (as well as the "gravatar" class) when the size of the gravatar is greater than 30px. How would I do this?

Thanks in advance :)


Solution

  • module UsersHelper
      def gravatar_for(user, options = {:size => 50})
        options[:size] > 30 ? @class = "gravatar round" : @class = "gravatar"
        gravatar_image_tag(user.email.downcase, :alt => user.name,
                                                :class => @class,
                                                :gravatar => options)
      end
    end