ruby on rails - Send_file does not down load the file -
i have application rails 3.2.22 , ruby 2.2. i'm trying implement send_file in application. download action triggered button click.
<input type='button' id='btn_save_log' value="save"/>
corresponding ajax call implementation click event given below.
$("#btn_save_log").on('click', function () { $.ajax({ url: "/a/b/save_trunk_logs?device_id="+deviceid+"&trunk_name="+trunkdevicename }) });
controller action code given below
def save_trunk_logs device_id = params['device_id'] trunk_name = params['trunk_name'] ||= "test" data ="" file = "#{trunk_name}.txt" trunk_logs = db taken(active record) file.open(file, "w+") |afile| afile.write("trunk name : #{trunk_name}\n") afile.write("*"*100) afile.write("\n") afile.write("time stamp"+"\t"+"log message\n") trunk_logs.each |msg| data =format_log_messages msg afile.write("#{data}\n") end end send_file file, :type => 'application/text; charset=utf-8', :disposition => 'attachment' end
every time hit action button click says file sent. not download in browser.
if manually hit route in browser, file getting downloaded.i want button click download file. i'm doing wrong.
any :)
Comments
Post a Comment