3
在我目前的Rails(Rails的2.3.5,红宝石1.8.7)的应用程序,如果我想能够定义像一个帮手:可选参数
def product_image_tag(product, size=nil)
html = ''
pi = product.product_images.first.filename
pi = "products/#{pi}"
pa = product.product_images.first.alt_text
if pi.nil? || pi.empty?
html = image_tag("http://placehold.it/200x200", :size => "200x200")
else
html = image_tag(pi, size)
end
html
end
...和然后从一个视图,或者把它:
<%= product_image_tag(p) %>
...或:
<%= product_image_tag(p, :size => 20x20) %>
换句话说,我希望能有这样的helper方法接受一个可选大小参数。什么是最好的方式去做这件事?
完美!非常感谢。 – yalestar 2010-09-14 20:51:57