1

In my rails project structure I have created a folder pages under the path db/pages . I would like to iterate through all the html.erb files in this db/pages directory and DoSomething with the filename of each of these files. All this should happen when I run rake db:seed so I have placed my code in seeds.rb

Below is my attempted code:

source_path = "/db/pages"

Dir.glob("#{source_path}/*.html.erb").each do |html_page|
  DoSomething html_page
end

This seems to be doing nothing when I run rake db:seed. Where have I gone wrong?

4

1 に答える 1

3

Try prepending Rails.root:

Dir.glob("#{Rails.root}#{source_path}/*.html.erb").each do |html_page|

An even more correct approach would be:

source_path = Rails.root.join('db', 'pages')

Dir.glob("#{source_path}/*.html.erb").each do |html_page|
于 2013-02-06T20:37:33.453 に答える