M.T Davis M.T Davis - 2 months ago 12
Ruby Question

Will_Paginate NoMethodError (undefined method `paginate'

I'm trying to in the "will_paginate" gem however when I push it to Heroku, I get the following error message on the Heroku server. The solution works perfectly in my development in environment.

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]:


Accounts Controller:

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 %>


Gem File
source '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


Then gem env is the same on both servers. I'm not sure what the problem is.

Answer

Remove gem 'will_paginate', '~> 3.0' from group :development, :test do to gem 'will_paginate', '~> 3.0', group: :production and that corrected the NoMethodError message in the Heroku log.