I am trying to download files in my rails app. I saw How to Create Download Link and used in my app. But when I tried to download, I get this error:
NoMethodError in ConfsController#download
undefined method `xml' for nil:NilClass
app/controllers/confs_controller.rb:61:in `download'
This is confs_controller:
def download
send_file @conf.xml.path, :type => @conf.xml_content_type, :filename => @conf.permalink
end
xml is my file. Its just a name like document in example. Now, I understand that this error appears because xml is nil. But why and how can I fix it?
The problem is not xml is
nil
. It is because@conf
isnil
. Hence it is not able to find xml fornil
class.Please make sure you have
@conf
object defined.