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 :)

有帮助吗?

解决方案

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top