Rails - 查看代表数据库中数据的图片
我正在寻找一些想法如何让星星像这个例子一样查看:
现在,我有一个表,其中一列表示黑色星星,一列表示灰色星星。(例如,在“Hüllenkontrolle”中,“2”表示 2 个黑色星星,“4”表示 4 个灰色星星)。所以我想到了根据数据库中的数字显示另一张图片的东西(1 = 1星,2 = 2星,3 = 3星,4 = 4星......)
我不知道在互联网上搜索什么或者如何意识到人们会看到的不是数字而是一些星星。有人知道如何实现这个吗?
有关我的数据库模型的一些信息: http://img6.imagebanana.com/img/kwenevyz /beziehungen.png
- 所有数据均在员工的 html.erb 中查看。
- 黑色星星代表 current_qualification-table(“qualificationstars”列),灰色星星代表预期的资格表(“qualificationstars”列)。 现在它在 html.erb 中的写法如下:
<% @employee.position.expected_qualifications.each do |expected_qualification| %>
<%=expected_qualification.qualificationstars %>
<%end%>
一些好消息!这似乎有效,
<% @employee.position.skills.zip(@employee.position.expected_qualifications, @employee.current_qualifications).each do |skill, expected_qualification, current_qualification| %>
<p>
<% (current_qualification.istqualifikation).times do %>
<%= image_tag("black.png") %>
<% end %>
<% (expected_qualification.sollqualifikation - current_qualification.istqualifikation).times do %>
<%= image_tag("grey.png") %>
<% end %>
</p>
<% end %>
这就是它现在在浏览器中的样子:
I'm searching for some idea how to let the stars view like on this example:
Right now, I have a table with a column for the black stars and a column for the grey stars.(in "Hüllenkontrolle" for example a "2" for 2 black stars and "4" for 4 grey stars). So I thought about something that shows another picture depending on which number is in the database (1 = 1 Star, 2 = 2 stars, 3 = 3 stars, 4 = 4 stars...)
I have no idea what to search on internet or how to realize that not the numbers will be viewed but some stars. Has anybody any idea how to implement this?
some information about my database model: http://img6.imagebanana.com/img/kwenevyz/beziehungen.png
- all data is viewed in the employee's html.erb.
- the black stars represent the current_qualification-table (column "qualificationstars"), the grey stars represent the expected qualification-table (column "qualificationstars").
Right now it's written in html.erb like this:
<% @employee.position.expected_qualifications.each do |expected_qualification| %>
<%= expected_qualification.qualificationstars %>
<%end%>
Some good news! This seems to work
<% @employee.position.skills.zip(@employee.position.expected_qualifications, @employee.current_qualifications).each do |skill, expected_qualification, current_qualification| %>
<p>
<% (current_qualification.istqualifikation).times do %>
<%= image_tag("black.png") %>
<% end %>
<% (expected_qualification.sollqualifikation - current_qualification.istqualifikation).times do %>
<%= image_tag("grey.png") %>
<% end %>
</p>
<% end %>
This is how it looks in browser now:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有一个黑色和灰色星星的图像文件,请在您的视图中尝试类似的操作:
编辑:
图像进入“public/images”(Rails < 3.1)或“app/assets/images”(Rails 3.1) )
编辑2:使用您的型号名称。
(我建议在数据库中将“qualificationstars”重命名为“stars”。qualification.qualificationstars 是多余的,而且有点麻烦。)
If you have an image file each for a black and grey star, try something like this in your view:
EDIT:
The images go into "public/images" (Rails < 3.1) or "app/assets/images" (Rails 3.1)
EDIT 2: Using your model names.
(I'd suggest renaming "qualificationstars" to simply "stars" in your DB. qualification.qualificationstars is redundant and a bit cumbersome.)