I am new to Rails and am having serious problems getting will_paginate to work with a nested resource.
I have two models: Statement and Invoice. will_paginate is working on Statement, but I can't get it to work with Invoice. I know that I will do something stupid, but I can not understand it, and the examples that I found in google will not work for me.
statement.rb class Statement < ActiveRecord::Base has_many :invoices def self.search(search, page) paginate :per_page => 19, :page => page, :conditions => ['company like ?', "%#{search}%"], :order => 'date_due DESC, company, supplier' end end statements_controller.rb <irrelevant code clipped for readability> def index
But I can't figure out how to make it work for invoices:
invoice.rb class Invoice < ActiveRecord::Base belongs_to :statement def self.search(search, page) paginate :per_page => 19, :page => page, :conditions => ['company like ?', "%#{search}%"], :order => 'employee' end end invoices_controller.rb class InvoicesController < ApplicationController before_filter :find_statement #TODO I can't get will_paginate to work wa nested resource def index #taken from the RAILSCAST 51, will_paginate podcast @invoices = Invoice.search(params[:search], params[:page]) end def find_statement @statement_id = params[:statement_id] return(redirect_to(statements_url)) unless @statement_id @statement = Statement.find(@statement_id) end end
And I'm trying to call it like this: <% = will_paginate (@invoices)%>
The most common error message when I play with this is: "The @statements variable seems empty. Have you forgotten to pass the collection object to will_paginate?"
I do not know what the problem is, or how to fix it. Thanks for any help and guidance!
Sue petersen
source share