問題
三項演算を実行するヘルパー メソッドがあります。結果オペランドは両方とも image_tag メソッドです。ビューからこのヘルパーを呼び出すと、":size" オプションが html の高さと幅のタグに変換されません。いずれかの image_tag メソッドをビュー ファイルに直接コピー アンド ペーストすると、すべて正常に動作します。
application_helper.rb
def display_portrait(candidate)
if candidate.portrait_url
image_tag(candidate.portrait_url.to_s, :size => "10x10")
else
image_tag("missing_portrait.png", :size => "10x10")
end
end
view.html.erb
<%= display_portrait candidate %> DOES NOT GENERATE HEIGHT AND WITH ATTR'S
<%= image_tag("missing_portrait.png", :size => "10x10") %> DOES GENERATE ATTR'S
ヘルパーは正しいソースでアンカーを生成します。高さと幅の属性のみが欠けています。
お時間を割いていただき、ありがとうございます。
マイケル