2014-04-11 46 views
0

你會如何轉換此.html.haml文件.html.erb?在瀏覽器中轉換html.haml - > html.erb

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

輸出應該是這樣的(如2帖子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> 
+1

你目前在瀏覽器中的輸出是什麼? – FabKremer

+0

我嘗試了不同的代碼,但沒有輸出正確的post.id和avg_score ...我更新了帖子 – Absurdim

回答

2

我想你應該不是使用「#{}」而是「<%=%>」。試試這個:

<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> 
0

.rating-總{數據:{ID:@ post.id,得分:@avg_score || 0}} 。總得分= @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不正確。

+0

類名無關緊要,這部分令人困惑:{data:{id:@ post.id,score:@ avg_score || 0}} – Absurdim