Ben wrote:
API is your friend.
ActionController::Streaming
send_file
I put this code block in files_controller.rb
def send_file(path, options = {}) #:doc:
raise MissingFile, “Cannot read file #{path}” unless
File.file?(path) and File.readable?(path)
options[:length] ||= File.size(path)
options[:filename] ||= File.basename(path)
send_file_headers! options
@performed_render = false
if options[:stream]
render :text => Proc.new { |response, output|
logger.info "Streaming file #{path}" unless logger.nil?
len = options[:buffer_size] || 4096
File.open(path, 'rb') do |file|
if output.respond_to?(:syswrite)
begin
while true
output.syswrite(file.sysread(len))
end
rescue EOFError
end
else
while buf = file.read(len)
output.write(buf)
end
end
end
}
else
logger.info "Sending file #{path}" unless logger.nil?
File.open(path, 'rb') { |file| render :text => file.read }
end
end
And add this line in my page
<%= link_to ‘file download’, :action => ‘send_file(download_filename)’
%>
where download_filename is a veriable <%=
download_filename=‘/images/myfile.xls’%>
when I click the link, it display error message as
“No action responded to send_file(download_filename)”
i guess syntax error in my code, while send_file().
plz help me with the syntax as i am new.
Tuhin