Case Insensitive in Rails + Urgently Need

Champs ..
Coming here for the first time .. :slight_smile:
Actually i am searching for a string in an array using an exists like
this ..
Area.exists?(:name = whatEverName)

But the crisis is that how can i call this case insensitively .. I mean
how can i check that this name(whatEverName) is available or not in Area
array case insensitively .. May be u guyz can find out other way than
exists also ..

Please float in your opinions ..

Sijo Kg wrote:

Area.exists?(:name => 'whatEverName'.downcase)

Nopes .. Not Working ..
Actually (:name => area_name) whole gives me a string which is to be
checked for existence ..
So probably we people can not do any operations on area_name alone ..
Correct .. q

If Area is an model object then you can put it in conditions itself as below
Area.find :all :conditions => [โ€˜name = lower(?)โ€™, area_name.down_case]

Nayak

Vishwanath Nayak wrote:

If Area is an model object then you can put it in conditions itself as
below
Area.find :all :conditions => ['name = lower(?)', area_name.down_case]

Nayak

Posted via http://www.ruby-forum.com/.

>

--
- NAYAK

Champs ..
Above both are not working ..
May be u people are not getting me properly .. :slight_smile:
Sorry, Area is an model object ..
I had tried these four .. But none of them are working fine for
"Area.exists? (:name => area_name)"

1) Area.find(:all, :conditions => ['name = lower(?)',
area_name.downcase])
2) Area.find (:all).collect{|a|
a.name.downcase}.include?(area_name.downcase)
3) Area.find(:all, :conditions => "name LIKE '%#{:name => area_name }'")
4) Area.exists?(['name LIKE ?', "%#{:name => area_name}%"])

Any other way .. ?

Thanks for yours response Champs .. Coming good .. :slight_smile:

This really should be working. Check the SQL generated in the log file
and test that directly against your database.
I would then tweak the SQL statement until you find what's working,
then work it back into ActiveRecord

Andrew Timberlake
http://ramblingsonrails.com

http://MyMvelope.com - The SIMPLE way to manage your savings

Andrew Timberlake wrote:

1) Area.find(:all, :conditions => ['name = lower(?)', area_name.downcase])

This really should be working. Check the SQL generated in the log file
and test that directly against your database.
I would then tweak the SQL statement until you find what's working,
then work it back into ActiveRecord

Andrew Timberlake
http://ramblingsonrails.com

http://MyMvelope.com - The SIMPLE way to manage your savings

Dude .. Sql itself is not generating ..
Actually what happens is i had given the creation of sql in if condition
..
I mean if this matches then only save ..
I'll tell u people the whole scenerio ..
Area is a model name ..

Area.exists?(:name => area_name) .. area name is coming from mine
textbox value and i am cheking it against to the records name of the
area table .. fine ..

Lets suppose now that my area table have a field Bangalore and mine
value coming from textbox is bangalore or may be banGalore .. i mean
whatever .. So how can i map this .. ?
And also if m giving Bangalore value it get stored ..
If this will map then only it'll save to the database ..
This is my question ..

Float your opinions ..

Sijo Kg wrote:

Area.find :all :conditions => ['lower(name) like (?)',
area_name.down_case]

Not Working .. :cry:

Area.find :all, :conditions => [โ€˜lower(name) = ?โ€™, area_name.down_case]