简体   繁体   English

rails3辅助方法的返回大小

[英]rails3 helper method return size

I have a gravatar method in the User_helper of a Rails3 application. 我在Rails3应用程序的User_helper中有一个gravatar方法。 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. 当前,此方法将默认大小设置为50px,但在整个应用程序的某些实现中已更改。 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. 我希望当图形图像的大小大于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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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