0
在我的Rails应用程序中,我有一些默认的gravatar图像,但我需要它在两页中的大小不同。 说,在第一页图像高度应该是50px,并在2nb页面 - 100px。如何在不同页面上显示相同图像的样式
问题是:我应该如何设置自己的代码以避免重复方法并实现我的目标? P.S.我相信我应该在“gravatar_show”中为“图片标签”添加一些更改,但是我所有的尝试都失败了。
def gravatar_for(user) # it's for 1'st page
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
image_tag(gravatar_url, alt: user.name, class: "gravatar img-rounded")
end
def gravatar_show(user) # it's for 2'nd page(show)
gravatar_for user
........# missing code......
end
======================================
当然,我可以复制和更改类和每一个在CSS中使用不同的类,但它看起来丑陋
def gravatar_for(user)
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
image_tag(gravatar_url, alt: user.name, class: "gravatar img-rounded")
end
def gravatar_show(user)
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
image_tag(gravatar_url, alt: user.name, class: "gravatar-show img-rounded")
end
感谢朋友,这只是工作的方式 这应该。 如果有人想知道,你的观点应该像:'= gravatar_for @user,:show' – dimitryeurope