0

In rails 4.0.0.

Why does this work

@employees = Employee.where(:club_id => session[:club_id]).page(params[:page])

but not this?

@payments = Payment.where(:club_id => session[:club_id], 
                           :trading_date => trading_date).page(params[:page])

On the second form I get an array error. I know how to fix it but I am perplexed as to why this occurs?

my error is this

NoMethodError (undefined method `page' for #<Array:0x007ff72845b380>):
app/controllers/payments_controller.rb:30:in `index'
markhorrocks
  • 1,199
  • 19
  • 82
  • 151
  • Post the exact error you are getting. – Andrew Marshall Jun 27 '13 at 03:25
  • edited to show error. – markhorrocks Jun 27 '13 at 03:39
  • is there any relation between `club_id` and `trading_date` means the conditions u have written are connected like (A and B) or (A or B) manner. if its logically connected then i think this should work well for you. '@payments = Payment.where(:club_id => session[:club_id]) and/or :trading_date => trading_date) .page(params[:page])' – Sagar.Patil Jun 27 '13 at 06:08
  • No relation, they are just separate columns in the payments tables. In this case, the club_id is read from the session and the trading date from params. This will not work as above unless I use the array helper in kaminari as @payments = Kaminari.paginate_array(myarray).page(params[:page]) – markhorrocks Jun 27 '13 at 10:00

1 Answers1

0

Are you sure you dont want to do

@payments = Payment.where(:club_id => session[:club_id])
  .where(:trading_date => trading_date)
  .page(params[:page])
house9
  • 20,359
  • 8
  • 55
  • 61