这是我的目标,我有一堆数据,一个包含名称值的名称数组,以及相同的重量,高度,颜色。
所以在我的控制器功能中,我有以下内容 我的数据库名称人员
def display
people= Person.all
end
在display.html.erb中:
<h1> Display Result</h1>
<div id='chart'>
<% @people.each do |x| %>
<svg width="<%=x.weight%>" height="<%=x.height%>">
<rect width = "<%=x.weight%>" height="<%=x.height%>" style="fill:<%=x.color%>;stroke-width:3;stroke:black">
<text fill="#ffffff",50,50><%= x.name %></text>
</svg>
<% end %>
</div>
答案 0 :(得分:0)
使用rails连接来修复高度和宽度。
<h1> Display Result</h1>
<div id='chart'>
<%= @people.each do |x| %>
<svg width = "500" height = "500">
<rect width="<%= x.weight %>" height="<%= x.height%>" style="fill:<%= x.color %>;stroke-width:3;stroke:black">
<text fill="#ffffff">x.name</text>
</svg>
<% end %>
</div>
<%= link_to 'Back', {:controller => 'people', :action => 'index'}, id:'proceedss' %>