ruby - rails to_xlsx Couldn't find all Vulnerabilities with 'id': (all, {}) (found 0 results, but was looking for 2) -


i have rails app (ruby 2.0.0, rails 4.2.1). export data excel using acts_as_xlsx gem.

here controller:

class vulnerabilitiescontroller < applicationcontroller   before_action :set_vulnerability, only: [:show, :edit, :update, :destroy]   # /vulnerabilities   # /vulnerabilities.json def index    @vulnerabilities = vulnerability.all     respond_to | format |     format.html # index.html.erb   format.json { render :json => @vulnerabilities }   format.xlsx {     send_data @vulnerabilities.to_xlsx.to_stream.read, :filename => 'costings.xlsx', :type => "application/vnd.openxmlformates-officedocument.spreadsheetml.sheet"   } end (…) 

here model:

class vulnerability < activerecord::base   acts_as_xlsx end 

but when click on button:

<%= link_to 'download', url_for(:format=>"xlsx") %> 

i have error:

couldn't find vulnerabilities 'id': (all, {}) (found 0 results, looking 2) 

screenshot:

activerecord recordnotfound

can help?

okay, after looking issue appears default acts_as_xlsx gem broken rails 4.1+. found repository has patch applied original acts_as_xlsx gem resolve issue, can found here:

https://github.com/straydogstudio/acts_as_xlsx

i updated gem pointed new repository

gem 'acts_as_xlsx',   :git => "git://github.com/straydogstudio/acts_as_xlsx.git" 

alternatively download zip , extract folder vendor directory (renaming acts_as_xlsx-master acts_as_xlsx). did in case patched repository disappears.

gem 'acts_as_xlsx',   :path => "vendor/acts_as_xlsx" 

kudos straydogstudio patch.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -