2015-11-06 102 views
0

我试图在“will_paginate”gem但是当我将它推到Heroku时,我在Heroku服务器上得到以下错误消息。 。Will_Paginate NoMethodError(undefined method`paginate'

2015-11-06T18:34:43.422821+00:00 app[web.1]: Processing by AccountsController#index as HTML 
     2015-11-06T18:34:43.509289+00:00 app[web.1]: 
     2015-11-06T18:34:43.509292+00:00 app[web.1]: NoMethodError (undefined method `paginate' for #<Account::ActiveRecord_Relation:0x007f39bc853bd8>): 
     2015-11-06T18:34:43.509293+00:00 app[web.1]: app/controllers/accounts_controller.rb:8:in `index' 
     2015-11-06T18:34:43.509294+00:00 app[web.1]: 
     2015-11-06T18:34:43.509295+00:00 app[web.1]: 

帐户控制:

class AccountsController < ApplicationController 
    before_action :authenticate_user! 
    before_action :set_account, only: [:show, :edit, :update, :destroy] 

    respond_to :html 

    def index 
    @account = Account.all.order("created_at DESC").paginate(:page => params[:page], :per_page => 8) 
    end 

    def show 
    @notes = Note.where(account_id: @account.id) #Where a note belong to the current account 
    end 

    def new 
    @account = Account.new 
    respond_with(@account) 
    end 

    def edit 
    end 

    def create 
    @account = Account.new(account_params) 
    @account.save 
    respond_with(@account) 
    end 

    def update 
    @account.update(account_params) 
    respond_with(@account) 
    end 

    def destroy 
    @account.destroy 
    respond_with(@account) 
    end 

    private 
    def set_account 
     @account = Account.find(params[:id]) 
    end 

    def account_params 
     params.require(:account).permit(:first_name, :last_name, :return_client, :program_id, :insurance_id, :address, :phone) 
    end 
end 

Index.html.erb

<br> 
<%= will_paginate @account , renderer: BootstrapPagination::Rails %> 
<br> 
<%= link_to 'Add Client', new_account_path %> 

宝石文件 源 'http://rubygems.org'

ruby '2.1.5' 
gem 'rails', '4.1.8' 
gem 'sqlite3', group: :development 
gem 'sass-rails', '~> 4.0.3' 
gem 'uglifier', '>= 1.3.0' 
gem 'coffee-rails', '~> 4.0.0' 
gem 'jquery-rails' 
gem 'turbolinks' 
gem 'jbuilder', '~> 2.0' 
gem 'sdoc', '~> 0.4.0',   group: :doc 
gem 'rails_12factor', group: :production 
gem 'pg', group: :production 
gem 'carrierwave' 
gem "fog" 
gem "figaro" 
gem 'tzinfo-data', platforms: [:mingw, :mswin] 
gem 'execjs' 
gem "mini_magick" 
gem 'devise' 
gem 'searchkick' 
group :development, :test do 
    gem 'rspec-rails', '~> 3.0' 
    gem 'will_paginate', '~> 3.0' 
    gem 'will_paginate-bootstrap' 
end 

然后宝石ENV是两台服务器上相同。我不确定问题是什么。

+0

你可以显示你的'Gemfile'吗?想看看你如何在那里添加'will_paginate' gem。您基本上需要确保gem正确安装在heroku上。 –

+0

如果您确定在heroku上安装了'will_paginate' gem并且仍然出现上述错误,请尝试在您的AccountsController中要求:'require'will_paginate'' –

+1

问题是'will_paginate'处于开发中而测试组只有这意味着当Heroku捆绑生产它不包括在内。因此'NoMethodError'。将'will_paginate'移出组定义,它应该正常工作 – engineersmnky

回答

1

删除gem 'will_paginate', '~> 3.0'group :development, :test dogem 'will_paginate', '~> 3.0', group: :production并纠正了Heroku日志中的NoMethodError消息。