Error using 'send_file' for ruby/rails - help appreciated
Posted
by
user1653279
on Stack Overflow
See other posts from Stack Overflow
or by user1653279
Published on 2012-09-24T21:35:50Z
Indexed on
2012/09/24
21:37 UTC
Read the original article
Hit count: 185
ruby-on-rails
I am trying to create a link to download a file from the file system. For this, I define the following in the "license_helper.rb" file:
def license_download_link(license, link_text = nil)
if link_text.blank?
link_text = image_tag("download_icon.png", :border => 0, :width => 32, :height =>32, :alt => 'Download License', :title => 'Download License')
end
tempLicenseFile = "tempLicense.xml"
File.open("#{tempLicenseFile}", 'w') do |tf|
tf.puts license.data
end
command = "./runLicenseEncoder.bat #{tempLicenseFile}"
generateEncryptedLicenseFile = `#{command}`
theLicenseFile = "license.xml"
link_to link_text, "license/download"
end
My "view" just calls this helper class:
<td><%= license_download_link(license, ' ') %></td>
In the 'routes.rb' file, I have defined the following:
map.licensedownload "license.xml", :controller => 'licenses', :action => 'download' map.download "/licenses/download", :controller => 'licenses', :action => 'download'
In the 'controller', I have 'licenses_controller.rb' which includes the following:
def download theLicense = @license licenseFileName = "license.xml"
send_file "#{licenseFileName}" , :type => "application/xml", :filename => "#{licenseFileName}"
end
However, I am unable to obtain the '@license' attribute from the database in the controller. Could someone please let me know what I am doing wrong here and why I am unable to get the value for "@license".
Thanks for your time, Regards, --- AJ
© Stack Overflow or respective owner