简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM