Missing will_paginate

I’m not sure why i am having this problem but when i execute a call to
the calls controller from a link

  • <%= link_to_unless_current 'My Call Book', { :controller => "calls", :action => "index" } %>
  • ::
  • I get the following error

    NoMethodError in CallsController#index

    undefined method `_of’ for #Class:0x2517c1c

    RAILS_ROOT: /Users/owenhmad/Sites/ministrytrackr/ministrytrackr
    Application Trace | Framework Trace | Full Trace

    /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/
    base.rb:1532:in method_missing_without_paginate' /Library/Ruby/Gems/1.8/gems/mislav-will_paginate-2.3.2/lib/ will_paginate/finder.rb:164:inmethod_missing’
    app/models/call.rb:23
    /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/
    dependencies.rb:203:in load_without_new_constant_marking' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:203:inload_file’
    /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/
    dependencies.rb:342:in `new_constants_in’

    part of my CallsController is

    class CallsController < ApplicationController
    before_filter :login_required, :only => [ :index, :new, :edit]

    def index
    @calls = Call.find(:all)
    @recent_calls = @current_user.calls.find(:all)
    @recent_calls = @current_user.calls.search(params[:search],
    params[:page])
    end

    def list
    @calls = @current_user.calls.find(:all)
    end

    def show
    @call = Call.find(params[:id])
    end

    And my call model is

    class Call < ActiveRecord::Base
    belongs_to :user
    has_many:visits, :dependent => :destroy
    has_many:visits do
    def latest
    find :all, :order => ‘id DESC’, :limit => 3
    end

    def all_latest
      find :all, :order => 'id DESC'
    end
    

    end

    def self.search(search, page)
    paginate :per_page => 4, :page => page,
    :conditions => [‘name like ?’, “%#{search}%”],
    :order => ‘name’
    end

    end

    It says in the error message `method_missing_without_paginate’

    I have will_paginate installed in rails as a gem and it shows up in my
    gem list. Any help to a beginner working on first real app after may
    books would be appreciated

    Thanks Owen

    The problem is in your controller action

    def index
    @calls = Call.find(:all)
    @recent_calls = @current_user.calls.find(:all)
    @recent_calls = @current_user.calls.search(params[:search],
    params[:page])
    end

    first, you are declaring @recent_calls twice, the first one
    (@recent_calls = @current_user.calls.find(:all)) will never work when
    the second is there.

    next, when you declare a method self.search in the class Call, you
    call it in the class!! so Call.search(params[:search], params[:page])
    willl return an array of calls. (Note: it will return them for ALL
    users, not just the current.

    Third, you are calling a method on class Array (which is what
    @current_user.calls returns) when you defined that method in the class
    Call.

    If you want to get a list of call objects from a user (i assume user
    has_many :calls, and call belongs_to :user) with a name like something
    and paginated. id do it like such:

    def index
    @recent_calls = @current_user.calls.paginate :per_page => 4, :page
    => params[:page],
    :conditions => [‘name like ? AND user_id = ?’, “%#{params[:search]}
    %”, @current_user.id],
    :order => ‘name’
    end

    if you use the method more than twice, then put it in the class, but
    you would also need to pass the user id.

    good luck

    Thank you so much Wolas for your reply and your suggestion got rid of
    my undefined mehod error And I coppied and pasted your suggestion but
    I now get the following error - I am not sure where to correct it

    SyntaxError in CallsController#index

    /Users/owenhmad/Sites/ministrytrackr/ministrytrackr/app/controllers/
    calls_controller.rb:6: syntax error, unexpected ‘\n’, expecting tASSOC
    /Users/owenhmad/Sites/ministrytrackr/ministrytrackr/app/controllers/
    calls_controller.rb:8: syntax error, unexpected tASSOC, expecting
    tCOLON2 or ‘[’ or ‘.’
    :conditions => [‘name like ? AND user_id = ?’,
    "%#{params[:search]}
    ^
    /Users/owenhmad/Sites/ministrytrackr/ministrytrackr/app/controllers/
    calls_controller.rb:9: syntax error, unexpected ‘,’, expecting kEND

    RAILS_ROOT: /Users/owenhmad/Sites/ministrytrackr/ministrytrackr

    Any suggestions would be appreciated - Owen

    As per usual, fred is correct

    On Aug 21, 5:39 pm, Frederick C. [email protected]

    On 21 Aug 2008, at 17:10, THEBIGO wrote:

    Thank you so much Wolas for your reply and your suggestion got rid of
    my undefined mehod error And I coppied and pasted your suggestion but
    I now get the following error - I am not sure where to correct it

    looks the email line wrapped it in a bad way:

    @recent_calls = @current_user.calls.paginate :per_page => 4, :page
    => params[:page],

    should be all on one line. (if you do put in line breaks put them
    after a ,)

    Fred

    Thank you again Fred and Wolas but now I am back to my undefined
    method and the following error

    NoMethodError in CallsController#index

    undefined method `_of’ for #Class:0x2355ca8

    RAILS_ROOT: /Users/owenhmad/Sites/ministrytrackr/ministrytrackr
    Application Trace | Framework Trace | Full Trace

    /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/
    base.rb:1532:in method_missing_without_paginate' /Library/Ruby/Gems/1.8/gems/mislav-will_paginate-2.3.2/lib/ will_paginate/finder.rb:164:inmethod_missing’
    app/models/call.rb:23
    /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/
    dependencies.rb:203:in `load_without_new_constant_marking’

    My index action is now
    def index
    @recent_calls = @current_user.calls.paginate :per_page =>
    4, :page => params[:page],
    :conditions => [‘name like ? AND user_id = ?’,
    “%#{params[:search]}
    %”, @current_user.id],
    :order => ‘name’

    end
    

    Notice the method-missing-without_paginate. Originally I have the
    pagination in my model as post one shows per Ryan B. and it worked
    in another version of
    this app so that is why it wasn’t in my original index action. I had
    moved it to the model.

    I don’t understand why the method_missing_without_paginate is there as
    my gem list shows I have the latest will_paginate and I am using rails
    2.0.2

    Any other suggestions?? Thanks in advance
    Owen

    On Aug 21, 9:46 am, ““Wolas!”” [email protected] wrote: @calls =
    Call.find(:all)

    Still havn’t figured out where the NoMethodError is from. Says
    wiil_paginate is missing
    and then the log file shows something about rb:23 in my call model.
    Does that mean line 23
    in the model? Any help please for a person in first year rails
    programing?

    Thanks in advance - Owen

    look in line 23 of the model Call yes

    Thanks for the reply. My model is
    class Call < ActiveRecord::Base
    belongs_to :user
    has_many:visits, :dependent => :destroy
    has_many:visits do
    def latest
    find :all, :order => ‘id DESC’, :limit => 3
    end

        def all_latest
            find :all, :order => 'id DESC'
        end
    
        #def self.search(search, page)
        #    paginate :per_page => 4, :page => page,
        #    :conditions => ['name like ?', "%#{search}%"],
        #    :order => 'name'
        #end
    end
    

    20 def self.search(search, page)
    21 paginate :per_page => 4, :page => page,
    22 :conditions => [‘name like ?’, “%#{search}%”],
    23 :order => ‘name’
    end

    ALL_FIELDS = %w(name address age area sex notes)
    VALID_SEX = ["Male", "Female"]
    validates_presence_of :name, :address, :age, :area
    validates_inclusion_of :sex,
                            :in => VALID_SEX,
                            :message => "must be male or female"
    

    end

    And line 23 is in the def for self.search conditions where I have

    :order => ‘name’ so I am not sure what is wron there

    thanks all for your help but I found my error and it involved an extra
    space in a rails method
    and the fact that when I changed some of the deffinitions in the model
    when I refrenced them I refrenced the old terms. thanks again - Owen

    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs