I am new to RoR,
How can I open a file via a clickable link.
suppose I have a excel file in a folder named “myfiles” in the public
directory.
as example
I have an excel(named as data.xls) file in “myfiles” directory
Now i want to allow the user to open the file by clicking a link in my
page.
Either method will work… the advantage of Ben’s method suggestion is
that
you can have Ruby code which runs each time the file is downloaded,
whereas
with my method, the file is just downloaded directly.
-N
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)”
Any syntax error in my code?
plz help me as i am new.