I am having trouble with a simple gallery search. I type in a segment of the address and i only seem to be getting results if I use the correct case. This is in my Gallery controller: def search @gallery = Gallery.find(:all, :include => :property, :conditions => "address LIKE ''%#{@params[:keywords]}%''") end On a different note: I am having trouble trying to access Gallery.property even though my Model associations have been setup. ie: Gallery belongs_to Property (foreign key -> property_id) Property has_many Galleries
On 3/10/06, bmgz <bmg2x@yahoo.com> wrote:> I am having trouble with a simple gallery search. > I type in a segment of the address and i only > seem to be getting results if I use the correct case. > > This is in my Gallery controller: > > def search > @gallery = Gallery.find(:all, :include => :property, > :conditions => "address LIKE ''%#{@params[:keywords]}%''") > endHi, If you''re using MySQL, that should be working fine. Under postgres, you''d need to use "ilike" rather than "like" for a case insensitive search. Not sure about other databases and what they use for case insensitive searches. Rick
On Sun, 2006-03-12 at 13:10 -0800, Rick Tessner wrote:> On 3/10/06, bmgz <bmg2x@yahoo.com> wrote: > > I am having trouble with a simple gallery search. > > I type in a segment of the address and i only > > seem to be getting results if I use the correct case. > > > > This is in my Gallery controller: > > > > def search > > @gallery = Gallery.find(:all, :include => :property, > > :conditions => "address LIKE ''%#{@params[:keywords]}%''") > > end > > Hi, > > If you''re using MySQL, that should be working fine. Under postgres, > you''d need to use "ilike" rather than "like" for a case insensitive > search. > > Not sure about other databases and what they use for case insensitive searches.---- seems to me that you abstract it by using (params[:keywords]).downcase and then you can do it ruby way instead of sql specific commands for one db or another but I''m not too certain about the usage above... #{@params[:keywords]} which just looks wrong and I would think that you have to do ''%'' + YOUR_SEARCH_PHRASE + ''%'' anyway...so it seems that there are a lot of things wrong with OP''s question. Craig
Craig White wrote: ...> seems to me that you abstract it by using (params[:keywords]).downcase > and then you can do it ruby way instead of sql specific commands for one > db or another but I''m not too certain about the usage above...The problem isn''t with the params[:keywords] being case sensitive but with the database itself (Postgres). The previous poster sorted this out by mentioning ILIKE. Nothing wring with choosing a database and actually USING it''s specific functions I supoose..> #{@params[:keywords]} which just looks wrong and I would think that youExplain? it works perfectly well. "you can execute ruby code in a string by using #{}" which is much neater than "doing" + this + "when" + you + "have alot of " + stuff_going_on
Rick Tessner wrote:> If you''re using MySQL, that should be working fine. Under postgres, > you''d need to use "ilike" rather than "like" for a case insensitiveThanks, I didn''t manage to stumble acrross ILIKE in the Postgres docs :-(
On Mon, 2006-03-13 at 09:24 +0200, Brendon Gleeson wrote:> Craig White wrote: > ... > > seems to me that you abstract it by using (params[:keywords]).downcase > > and then you can do it ruby way instead of sql specific commands for one > > db or another but I''m not too certain about the usage above... > > The problem isn''t with the params[:keywords] being case sensitive but with > the database itself (Postgres). The previous poster sorted this out by > mentioning ILIKE. Nothing wring with choosing a database and actually USING > it''s specific functions I supoose..---- not at all - I was just offering a db independent method as opposed to a hard coded db specific method...I use postgres myself but that wasn''t the point. ----> > > > #{@params[:keywords]} which just looks wrong and I would think that you > > Explain? it works perfectly well. "you can execute ruby code in a string > by using #{}" which is much neater than "doing" + this + "when" + you + > "have alot of " + stuff_going_on---- well the + stuff seems more obvious to me but the thing that caught my eye was using the instance variable @params which is confusing because of the nature of params being the object passed by GET/POST. One of the more confusing things to me was the usage of @model vs. @models and what I finally figured out was that the difference was more in my own expectations and thus the choice of the names of instance variables becomes one of easy comprehension. Craig