Problem with Rails Active Admin Resources

I recently looked at railscast 284 about the active admin and wanted to implement it in my web application, however I am having a problem when I add a resource. I get the following message every time I try to go to the created tab:

NameError in Admin::LoadsController#index undefined local variable or method `per' for []:ActiveRecord::Relation Rails.root: /Users/thomascioppettini/rails_projects/want-freight Application Trace | Framework Trace | Full Trace Request Parameters: {"order"=>"id_desc"} Show session dump Show env dump Response Headers: 

Not

The only thing I can think of that can affect the application is to add a recaptcha for development, on which the active administrator depends.

+6
source share
4 answers

For me, this seems like a pagination problem. What gem are you using? You should give more details about your decision. Can you show us your resource file from the admin directory? What version of rails and which ActiveAdmin are you using?

+3
source

If you are using the will_paginate gem, install the version in 3.0.pre2. I used ~>3.0.pre2 , which automatically updated to 3.0.2 when I ran bundle update Reverting, fixed the problem. If you are using a bundler, the line is like this:

 gem "will_paginate", "3.0.pre2" 
+3
source

I agree with dawid. This is a pagiantion bug. Add the Kaminari Gemfile to you. According to active admin docs, it uses fireplaces to paginate .. will_paginate will also work for you as described in swilliams ...

+2
source

As I understand it, active_admin no longer supports will_paginate. But if you do not want to rewrite your pagination in Kaminari, you can fix this problem by adding some code to the initializers.

 # config/initializers/will_paginate.rb if defined?(WillPaginate) module WillPaginate module ActiveRecord module RelationMethods alias_method :per, :per_page alias_method :num_pages, :total_pages end end end end module ActiveRecord class Relation alias_method :total_count, :count end end 
+1
source

Source: https://habr.com/ru/post/897951/


All Articles