Undefined method "total_entries" after upgrading Rails 2.2.2 to 2.3.5

I am upgrading a Rails application from 2.2.2 to 2.3.5. The only remaining error is when I call total_entriesto create jqgrid.

Error:

NoMethodError (undefined method `total_entries' for #<Array:0xbbe9ab0>)

Code snippet:

@route = Route.find(
  :all,
  :conditions => "id in (#{params[:id]})"
) {
  if params[:page].present? then
    paginate :page => params[:page], :per_page => params[:rows]
    order_by "#{params[:sidx]} #{params[:sord]}"
  end
}

respond_to do |format|
  format.html # show.html.erb
  format.xml  { render :xml => @route }
  format.json  { render :json => @route }
  format.jgrid {
    render :json => @route.to_jqgrid_json(
      [
        :id, :name
      ],
      params[:page],
      params[:rows],
      @route.total_entries
    )
  }
end

Any ideas? Thank!

EDIT

I can make it work by deleting the block used after find. I also had to move order_byused by the squirrel plugin when I received an undefined method call for it.

I do not like the fact that it is less DRY than the previous code, using conditionsin several places. Is there a better way to do this with Rails 2.3.5, will_paginate and squirrel?

  if params[:page].present? then
    @route = Route.paginate :conditions => "id in (#{params[:id]})", :page => params[:page], :per_page => params[:rows], :order => "`#{params[:sidx]}` #{params[:sord]}"
  else
    @route = Route.find(:all, :conditions => "id in (#{params[:id]})")
  end

EDIT 2

, Ruby 1.8.7 Rails 2.2.2 Ruby 1.9.1 Rails 2.3.5. - 1.8.7 1.9.1, , ActiveRecord find ?

+3
1

Rails 2.3.5 find (: all,...) , , , - , , . .

, , , , :

class Route < ActiveRecord::Base
  named_scope :with_ids, lambda { |*ids| {
    :conditions => { :id => ids.flatten }
  }}
end

:

@routes = Route.with_ids(params[:id])
+1

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


All Articles