Forum: Ruby on Rails error with send_file.. please help me...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C1923672c96592b38c570691547889ee?d=identicon&s=25 tuhin (Guest)
on 2007-02-22 11:38
Ben wrote:
> API is your friend.
> http://api.rubyonrails.org/classes/ActionControlle...
> 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
This topic is locked and can not be replied to.