Duilio Ruggiero wrote: > RichardOnRails wrote: >> Hi, >> >> I'm developing a small Rails 2.2.0 app. I have a slightly modified >> scaffold-generated file, >> PayrollSys\app\controllers\cvs_items_controller.rb, as follows: >> >> class CvsItemsController < ApplicationController >> # GET /cvs_items >> # GET /cvs_items.xml >> require 'find' # Added >> >> def index >> logger.info "==> index in cvs_items_controller.rb" >> # @cvs_items = CvsItem.find(:all) >> @cvs_items = get_csv_filenames_attributes() # Replacement >> >> [snip] >> >> protected >> def reload >> logger.info "==> Reload in cvs_items_controller.rb -- RLM " >> end >> >> def get_csv_filenames_attributes >> csv_data_dir = "../../public/data/csv" > > do you mean "../../../public/data/csv"? > or you have a public dir under the app dir? > > yes it is strange but you need to go 1 dir more back...
no, my error is relative to the dir where you start rails if you use ruby script/server and csv_data_dir = "public/data/csv" it works > >> values = [] >> Find.find(csv_data_dir) do |item| >> next unless File.file?(item) >> values << item >> end >> values >> end >> end >> >> Using a logger, I have confirmed that no filenames have been returned >> by File.find and that the values array remains zero length. > > probably you are looking in the wrong dir > >> >> However, the exact same method (without the "def" and its closing >> "end"), when added to a brother file in the same directory, correctly >> lists the two .csv files in the >> PayrollSys\public\data\csv directory (when a puts is prepended to the >> closing "values" symbol). >> >> Is there some security method that precludes accessing the files? >> Would the tableless plugin be relevant, though I do want ActiveRecord >> to access the application database(s). >> >> Thanks in Advance, >> Richard > > try this: > > protected > def reload > logger.info "==> Reload in cvs_items_controller.rb -- RLM " > end > > def get_csv_filenames_attributes > csv_data_dir = File.expand_path(File.dirname(__FILE__) + > "../../../public/data/csv/") > logger.info "==> csv_data_dir: #{csv_data_dir}" #print the dir so > you can check if it is correct > values = [] > Find.find(csv_data_dir) do |item| > logger.info "==> item in csv_data_dir: #{item}" > next unless File.file?(item) > values << item > end > values > end > > Hope this help > > Duilio Ruggiero Errata corrige protected def reload logger.info "==> Reload in cvs_items_controller.rb -- RLM " end def get_csv_filenames_attributes csv_data_dir = File.expand_path(File.dirname(__FILE__) + "/../../public/data/csv/") values = [] logger.info "==> csv_data_dir: #{csv_data_dir}" Find.find(csv_data_dir) do |item| next unless File.file?(item) logger.info "==> file in csv_data_dir: #{item}" values << item end values end I hope this is correct ;) Duilio Ruggiero PS: I'm sorry for my English -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---