Har*_*old 0 ruby-on-rails image helper
你好,
我正在尝试在轨道上创建一个ruby的网站,我正在建立一个帮助,以显示5个星级的评级.到目前为止我有:
def stars(score)
html = ""
if score >= 1
image_tag "star.png", :alt => 'one'
else
html << ""
end
if score >= 2
html << (image_tag "star.png", :alt => 'one')
else
html << ""
end
if score >= 3
html << (image_tag "star.png", :alt => 'one')
else
html << ""
end
if score >= 4
html << (image_tag "star.png", :alt => 'one')
else
html << ""
end
if score >= 5
html << (image_tag "star.png", :alt => 'one')
else
html << ""
end
end
Run Code Online (Sandbox Code Playgroud)
但这似乎不是一个非常好的技术,它是将html写入屏幕而不是显示图像.
任何人都有什么想法我能做什么?
谢谢,Haziba
def stars(score)
(image_tag("star.png", :alt => 'one') * score).html_safe
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
121 次 |
| 最近记录: |