我正在尝试将自己的百分比放在Bootstrap进度条中。 float被传递到视图完全正常,但由于某种原因,Bootstrap进度条不想读取它。我将首先猜测我没有正确转义style
标签。
观点:
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="#{ <% @app.completion_status %> }" aria-valuemin="0" aria-valuemax="100" style="width: '#{raw(<%= number_to_percentage(@app.completion_status) %>)}';">
<%= @app.completion_status %>%
</div>
</div>
仔细看看:
style="width: '#{raw(<%= number_to_percentage(@app.completion_status) %>)}';"
The value attempting to be passed and converted to a percentage is: `33.3333333333333` (one third)
控制器:
def set_completion
@app = App.find(params[:id])
@app.update_attribute(:completion_status,
(((@app.elements.where(completion: true).count) / (@app.elements.count).to_f) * 100 )
)
end
答案 0 :(得分:1)
您是否尝试过切换'和“?
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="#{ <% @app.completion_status %> }" aria-valuemin="0" aria-valuemax="100" style='width: "#{raw(<%= number_to_percentage(@app.completion_status) %>)}";'>
<%= @app.completion_status %>%
</div>
</div>
答案 1 :(得分:1)
乍一看,我看到你在erb标签之外使用红宝石插值,这可能是个问题。编辑::尝试以下
style="width: <%= number_to_percentage(@app.completion_status) %>"
下面是我刚建立的一个,所以请尝试按照这个并将插值保留在ERB标记内!
<div class="progress-bar progress-bar-info progress-bar-striped"
role="progressbar" aria-valuenow="<%=@email_usage%>" aria-valuemin="0"
aria-valuemax="100" style="width: <%=@email_usage%>%">