0
0

More than 3 years have passed since last update.

content_tag

Posted at

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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0