John Aneston
2006-Dec-12 05:52 UTC
Paginate!! passing params[] for conditions for DB search
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2006-Dec-12 06:29 UTC
Re: Paginate!! passing params[] for conditions for DB search
> 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 ()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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
John Aneston
2006-Dec-12 06:51 UTC
Re: Paginate!! passing params[] for conditions for DB search
Philip Hallstrom 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... > > -philipok 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Paul --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Gustav Paul > Sent: 12 December 2006 13:18 > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Subject: [Rails] rake stats not picking up RSpec > > > Hi > > Is there a way to have ''rake stats'' read my specs as tests and log my > specs'' lines of code accordingly?Try:> rake spec:statsetupThat should setup stats to use rspec. hth -- Richard Livsey 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---