Ruby on Rails:为文件夹中的每个文件生成HTML [英] Ruby on Rails: Generate HTML for each file in a folder

查看:42
本文介绍了Ruby on Rails:为文件夹中的每个文件生成HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个文件夹,其中包含一些* .ogg小文件,我希望将它们插入到/ public文件夹中的html.erb页面中。

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.

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

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.

结果页面将是可播放视频的列表。

The resulting page will be a list of playable videos.

任何建议都很棒。

推荐答案

# 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" />

这篇关于Ruby on Rails:为文件夹中的每个文件生成HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆