Hey guys,
I have stuck on pagination by passing values from a text_field for
searching a db, It works on the first page and it throws an SQL error
while clicking the second page. Below is my code, guys definetly help
needed, thanks in advance.
i pass search params from the text_field in .rhtml
conditions = @params[‘search’].to_s.split(’ ‘).collect {|query_search|
“requirements.position_title LIKE ‘%#{query_search}%’”}.join(’ OR ')
requirement = Requirement.find_all
@requirement_pages, @requirements = paginate :requirements, :per_page =>
5, :order => ‘opening_date DESC’, :conditions => conditions
error i get is about count(*) which i dont use anywhere in the code. and
The db config of mine is MySQL server 5.0
Mysql::Error: #42000You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near ‘)’ at line 1: SELECT count(*) AS count_all FROM
requirements WHERE ()
regards
john aneston
syntax to use near ‘)’ at line 1: SELECT count(*) AS count_all FROM
requirements WHERE ()
Looks like on page 2, @params[‘search’] doesn’t contain any spaces so
there’s nothing to split, collect, or join so ‘conditions’ is nil
resulting in “WHERE ()” which is invalid.
Why @params[‘search’] instead of params[:search]?
Also, why are you finding all the requirements right before paginating?
Seems like a redundant effort?
Check your logs to see what rails sees in it’s params when you hit page
two…
-philip
Philip H. wrote:
syntax to use near ‘)’ at line 1: SELECT count(*) AS count_all FROM
requirements WHERE ()
Looks like on page 2, @params[‘search’] doesn’t contain any spaces so
there’s nothing to split, collect, or join so ‘conditions’ is nil
resulting in “WHERE ()” which is invalid.
Why @params[‘search’] instead of params[:search]?
Also, why are you finding all the requirements right before paginating?
Seems like a redundant effort?
Check your logs to see what rails sees in it’s params when you hit page
two…
-philip
ok i got that Philip,
thanks buddy… i have passed the parameter again from the .rhtml on the
pagination link it works fine now. And i will check about the redundancy
too which you are saying. Now i ubderstand much about it.
thanks once again.
regards
john aneston
i had similiar problem and mine may be different. when i was running
into errors when trying to click on page 2 of my paginate object, it was
due to params being passed as null and not being carried offer. this was
easily solved by keeping track of my params variables via session
cookies.
Hi
Is there a way to have ‘rake stats’ read my specs as tests and log my
specs’ lines of code accordingly?
Thanks in advance.
Gustav P.
Is there a way to have ‘rake stats’ read my specs as tests and log my
specs’ lines of code accordingly?
Try:
rake spec:statsetup
That should setup stats to use rspec.
hth
–
Richard L.
Head of Agile Development, CitySafe
http://citysafe.org … CitySafe
http://thatsprogress.com … The Fitness Community (soon)
http://livsey.org … Blog : Musings of a Rails Developer
i know i had some issues passing parameters with the pagination links,
don’t know if this is what you’re dealing with; but go for
<%= pagination_links(@requirement_pages), :params => {:search =>
params[:search]} %>
and when u reach the second page via this link, you won’t get the error,
as the parameters have been passed…