Dans mes rails actuels (Rails 2.3.5, Ruby 1.8.7) application, si je voudrais être en mesure de définir une aide comme:Paramètres optionnels pour Rails image Aide
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
... et puis l'appeler d'une vue soit:
<%= product_image_tag(p) %>
... ou:
<%= product_image_tag(p, :size => 20x20) %>
en d'autres termes, je voudrais être en mesure d'avoir cette méthode d'assistance prendre une option paramètre de taille. Quel serait le meilleur moyen d'y parvenir?
Parfait! Merci beaucoup. – yalestar