Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Active Admin resource problem

I recently have watched railscast 284 about active admin and wanted to implement it into my web app, however I am running into an issue when I add a resource. I get the following message every time I try to navigate 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:

None

The only thing I can think of that may affect the application is adding a recaptcha to devise, which active admin depends on.

like image 469
tomciopp Avatar asked Sep 24 '11 01:09

tomciopp


4 Answers

For me, it looks like this is a pagination problem. What gem are you using? You should give as more details about your settup. Can you show us your resource file from admin directory? What version of rails and what ActiveAdmin are you using ?

like image 177
Dawid Woźniak Avatar answered Sep 21 '22 14:09

Dawid Woźniak


If you are using the will_paginate gem, set the version to 3.0.pre2. I was using ~>3.0.pre2, which auto-updated to 3.0.2 when I ran a bundle update Reverting fixed the issue. If you're using Bundler, the line is this:

gem "will_paginate", "3.0.pre2"
like image 28
swilliams Avatar answered Sep 18 '22 14:09

swilliams


I agree with Dawaid. It is a pagiantion error. Add "Kaminari" gem to you Gemfile. According to active admin docs, it is using kaminari for pagination.. will_paginate will also work for you as swilliams described...

like image 29
Hardik Joshi Avatar answered Sep 19 '22 14:09

Hardik Joshi


As I understand active_admin doesn't support will_paginate anymore. But if you don't want to rewrite your pagination to Kaminari you can fix this problem with putting some code to 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
like image 26
jizak Avatar answered Sep 18 '22 14:09

jizak