ruby - Iterate through files in rails directory, do something with filename? -



ruby - Iterate through files in rails directory, do something with filename? -

in rails project construction have created folder pages under path db/pages . iterate through html.erb files in db/pages directory , dosomething filename of each of these files. should happen when run rake db:seed have placed code in seeds.rb

below attempted code:

source_path = "/db/pages" dir.glob("#{source_path}/*.html.erb").each |html_page| dosomething html_page end

this seems doing nil when run rake db:seed. have gone wrong?

try prepending rails.root:

dir.glob("#{rails.root}#{source_path}/*.html.erb").each |html_page|

an more right approach be:

source_path = rails.root.join('db', 'pages') dir.glob("#{source_path}/*.html.erb").each |html_page|

ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -