如何将此.html.haml文件转换为.html.erb?
.rating-total{data: {id: @post.id, score: @avg_score || 0 }}
.total-score= @avg_score ? @avg_score.round(1) : 0
浏览器中的输出应该是这样的(例如,2是post id):
<div class='rating-total' data-id='2' data-score='0'></div>
<div class='total-score'>0.0</div>
我试过这个,但我没有在浏览器中获得正确的输出:
<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>
在浏览器中输出:
<div class="rating-total" data-id="#{@post.id}" data-score= "#{@avg_score || 0}"></div>
<div class="total-score">2.3</div>
答案 0 :(得分:2)
我认为你没有使用&#34;#{}&#34;但&#34;&lt;%=%&gt;&#34;代替。试试这个:
<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>
答案 1 :(得分:0)
.rating-total {data:{id:@ post.id,得分:@ 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>
您的total_score
不正确。