Ruby on Rails:为文件夹中的每个文件生成HTML

时间:2023-02-05 22:36:55

I currently have a folder with a list of small *.ogg files that I would like to insert into an html.erb page in my /public folder.

我目前有一个包含小* .ogg文件列表的文件夹,我想将其插入到我/ public文件夹的html.erb页面中。

The code is within video tags - I want to use Ruby to scan the folder and produce a video snippet for each video it finds in the folder. The code will stay the same between videos, except for the video filename.

代码在视频标签内 - 我想使用Ruby扫描文件夹并为它在文件夹中找到的每个视频生成视频片段。除视频文件名外,视频之间的代码保持不变。

The resulting page will be a list of playable videos.

生成的页面将是可播放视频的列表。

Any advice would be awesome.

任何建议都很棒。

1 个解决方案

#1


3  

# assumes the current dir contains the ogg files
html = ''
Dir.glob("*.ogg") do |file|
  html += "<a href=\"#{file}\" />"
end
puts html
# <a href="a.ogg" /><a href="b.ogg" />

#1


3  

# assumes the current dir contains the ogg files
html = ''
Dir.glob("*.ogg") do |file|
  html += "<a href=\"#{file}\" />"
end
puts html
# <a href="a.ogg" /><a href="b.ogg" />