Pergunta

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?

Foi útil?

Solução

The problem is not xml is nil. It is because @conf is nil. Hence it is not able to find xml for nil class.

Please make sure you have @conf object defined.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top