# Strange Race Condition?

**URL:** <https://www.ruby-forum.com/t/strange-race-condition/112228>\
**Category:** Rails\
**Created:** [August 16, 2007, 5:00pm UTC](https://www.ruby-forum.com/t/strange-race-condition/112228 "2007-08-16T17:00:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@Glen](https://www.ruby-forum.com/u/Glen)\
**Post date:** [August 16, 2007, 5:00pm UTC](https://www.ruby-forum.com/t/strange-race-condition/112228/1 "2007-08-16T17:00:23Z")

</div>

I have a very odd situation.

I have a method in my application controller:

def manual\_location(city, region, country)  
result = Location.user\_created(params[:new\_city],  
params[:new\_region], params[:new\_country])

```
case result when true then
  return Location.find(:first, :conditions => ["city = ? AND

```

region = ? AND country = ?", params[:new\_city], params[:new\_region],  
params[:new\_country]]).id  
when -1 then  
flash[:error] = “There was an error saving the location to the  
database.”  
when false then  
flash[:error] = “You didn’t provide all three values: City,  
Region, and Country”  
end  
return false  
end

This is the user\_created method from the Location model:

def self.user\_created(city, region, country)  
unless (city && region && country) # Unless we have all three it  
is invalid  
return false  
end

```
# Either case below it should exist by the time we finish so

```

return true

```
check = Location.find(:first, :conditions => ["city = ? AND region

```

= ? AND country = ?", city, region, country])

```
if check
  return true
end

location = Location.new(:city => city, :region => region, :country

```

=\> country)

```
if location.save
  return true
else
  return -1
end

```

end

When I call the method from one controller it works no problem,  
however when I call it from a different contoller I get NilClass  
errors.

This doesn’t happen at all on the Windows box I have at work, I only  
get the odd behavior on my Linux machine at home.

Does anyone have any ideas?

I realize the model method is ugly, I wrote it late at night and  
haven’t gotten around to cleaning it up.
