You are on the right track. I would do this:
def product_image_tag(product, options = {})
options[:size] ||= "200x200"
if img = product.product_images.first
image_tag("products/#{img.filename}", :alt => img.alt_text, :size => options[:size])
else
image_tag("http://placehold.it/#{options[:size]}", :size => options[:size])
end
end
Explanations:
Setting the final parameter to an empty hash is a common Ruby idiom, since you can call a type method product_image_tag(product, :a => '1', :b => '2', :c => '3', ...)without making extra arguments hash with {}.
options[:size] ||= "200x200" size: 200x200, .
if img = product.product_images.first - Ruby , . , product.product_images.first nil ( ), placehold.it, .