Rails - 查看代表数据库中数据的图片

发布于 2024-11-24 22:19:46 字数 1577 浏览 2 评论 0原文

我正在寻找一些想法如何让星星像这个例子一样查看:

在此处输入图像描述

现在,我有一个表,其中一列表示黑色星星,一列表示灰色星星。(例如,在“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:

enter image description here

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:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕嗳→ 2024-12-01 22:19:46

如果您有一个黑色和灰色星星的图像文件,请在您的视图中尝试类似的操作:

<% @employee.position.expected_qualifications.each do |expected_qualification| %>

<% @employee.current_qualification.qualificationstars.times do %>
<%= image_tag("black_star.png") %>
<% end %>

<% [expected_qualification.qualificationstars - @employee.current_qualification.qualificationstars].times do %>
<%= image_tag("grey_star.png")  %>
<% end %>

<% end %>

编辑:

图像进入“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:

<% @employee.position.expected_qualifications.each do |expected_qualification| %>

<% @employee.current_qualification.qualificationstars.times do %>
<%= image_tag("black_star.png") %>
<% end %>

<% [expected_qualification.qualificationstars - @employee.current_qualification.qualificationstars].times do %>
<%= image_tag("grey_star.png")  %>
<% end %>

<% end %>

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文