content_tag
はのちに消える説あるけどコードが冗長だったので修正しました。
修正前
<% if @provider.key == "noe-jx-group" %>
<div class="e__saving"><span class="e__tag">割引額</span><span class="e__number e__deals"><%= service['discount'].to_f %></span>円<% if SetPlan.is_discount_from_energy?(service) %>/kWh<% elsif SetPlan.monthly?(service) %>/月<% elsif SetPlan.yearly?(service) %>/年<% end %></div>
<% end %>
修正後
<%= discount_text(service, @provider) %>
try_helper.rb
def discount_text(service, provider)
content_tag(:div, class: "e__saving") do
discount_text = content_tag(:span, "割引額", class: "e__tag")
discount_value = content_tag(:span, provider.key == "noe-jx-group" ? service['discount'].to_f : service['discount'].to_i, class: "e__number e__deals" ) + "円"
discount_from_energy = if SetPlan.is_discount_from_energy?(service)
"/kWh"
elsif SetPlan.yearly?(service)
"/年"
elsif SetPlan.monthly?(service)
"/月"
end
discount_text + discount_value + discount_from_energy
end
end