I have a model called Report and I’m trying to create a text file that
is saved in a /public/report directory.
I’ve had a look at the ruby api but I can’t seem to get this working.
The current code I have is:
#report.rb
class Report < ActiveRecord::Base
after_save :write_file
def write_file
if @file_data
File.makedirs("#{RAILS_ROOT}/report")
File.open("#{RAILS_ROOT}/report/waiting.adc", “w”) { |file|
file.write(“hello world”) }
end
end
end
#report_controller.rb
def new @report = File.new
end
def create
if @report.save
flash[:notice]=‘report’
else
render :action=>‘new’
end
end