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 …

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

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

O sorry here here you have to get the db records to be case insensitive
If Area is just an array (Not clear) then can do
Area.include?(‘whatEverName’.downacase)
If its a model name its field
Area.find(:all).collect {|a|
a.name.downcase}.include?(‘whatEverName’.downacase)

Sijo

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

On Fri, Jun 19, 2009 at 3:20 PM, Sijo Kg
[email protected]wrote:

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

  • 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

On Fri, Jun 19, 2009 at 3:20 PM, Sijo Kg
[email protected]wrote:

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:

On Fri, Jun 19, 2009 at 12:08 PM, Hemant
Bhargava[email protected] 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 T.
http://ramblingsonrails.com

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

Andrew T. wrote:

On Fri, Jun 19, 2009 at 12:08 PM, Hemant
Bhargava[email protected] 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 T.
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 … :’(

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

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

On Fri, Jun 19, 2009 at 4:35 PM, Hemant B. <
[email protected]> wrote:

  • NAYAK