在我当前的 Rails(Rails 2.3.5,Ruby 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) %>
换句话说,我希望能够让这个辅助方法采用可选的大小参数。解决此问题的最佳方法是什么?