Absurdim
Absurdim

Reputation: 233

Convert html.haml -> html.erb

How would you convert this .html.haml file to .html.erb?

.rating-total{data: {id: @post.id, score: @avg_score || 0 }}
.total-score= @avg_score ? @avg_score.round(1) : 0

output in the browser should be something like this(e.g. 2 is post id):

<div class='rating-total' data-id='2' data-score='0'></div> 
<div class='total-score'>0.0</div>

I tried with this, but I don't get the proper output in the browser:

<div class="rating-total" data-id="#{@post.id}" data-score= "#{@avg_score || 0}"></div>
<div class="total-score">
  <%= @avg_score ? @avg_score.round(1) : 0 %>
</div>

output in the browser:

<div class="rating-total" data-id="#{@post.id}" data-score= "#{@avg_score || 0}"></div>
<div class="total-score">2.3</div>

Upvotes: 0

Views: 236

Answers (2)

FabKremer
FabKremer

Reputation: 2169

I think you shoudn't use the "#{}" but "<%= %>" instead. Try this:

<div class="rating-total" data-id= <%= @post.id %> data-score= <%= @avg_score || 0 %>></div>
<div class="total-score">
  <%= @avg_score ? @avg_score.round(1) : 0 %>
</div>

Upvotes: 2

Trip
Trip

Reputation: 27114

.rating-total{data: {id: @post.id, score: @avg_score || 0 }} .total-score= @avg_score ? @avg_score.round(1) : 0

<div class="rating-total" data-id="#{@post.id}" data-score="#{@avg_score || 0}"></div>
<div class="total-score"><%= @avg_score ? @avg_score.round(1) : 0 %></div>

Your total_score is incorrect.

Upvotes: 0

Related Questions