I've got this in my controller:
@artists = Artist.where("artist LIKE ?", "%#{params[:term]}%").limit(500).paginate(params[:page])
And am getting the can't dup NilClass
error.
Now, params[:term] and params[:page] are 2 different variables so why should the error appear? If I remove the second params variable, the error is gone.
It will still appear even if I do this:
page = params[:page]
Then below:
paginate(page)
I'd like to understand why this is happening and how to fix it, how to use 2 variables from params() in the same line without that error.
Edit
I've discovered that substituting an integer for params[:page] results in a slightly different error: can't dup FixNum
so maybe the issue is not with params but something else. Still don't know how to solve it though.
My mistake. I apologize profusely for this, but I was using paginate inappropriately. I wish I could delete this question, but there doesn't seem to be a way. The proper way to use it is:
paginate(:page => params[:page]
I guess that's what happens when you've been staring at code for too long :)
Maybe it will help others deal with Paginate. I really like it, but the errors could really be a little more descriptive.
For example, I will always get an unknown method error unless I do this:
<%= will_paginate @artists if @artists.respond_to? :total_pages %>
Thanks for not removing this question. I was being equally neglegent and changing: paginate( params[ :page ] ) to paginate( page: params[ :page ] ) fixed it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With