# Is there a better way to do this?

**URL:** <https://www.ruby-forum.com/t/is-there-a-better-way-to-do-this/145768>\
**Category:** Rails\
**Created:** [August 13, 2008, 8:24pm UTC](https://www.ruby-forum.com/t/is-there-a-better-way-to-do-this/145768 "2008-08-13T20:24:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![max](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e5b9ba/32.png) [@max](https://www.ruby-forum.com/u/max)\
**Post date:** [August 13, 2008, 8:24pm UTC](https://www.ruby-forum.com/t/is-there-a-better-way-to-do-this/145768/1 "2008-08-13T20:24:33Z")

</div>

Im trying to update a ‘default’ field in a model to false, only rows  
that belong to a specific user  
the idea is to have only one default per user in that table… this is  
how im doing it

def default  
@neighborhood = UserNeighborhood.find(params[:id])  
@neighborhoods = UserNeighborhood.find(:all,:conditions =\>  
[“user\_id = ?”,current\_user.id])  
@neighborhoods.each do |neighborhood|  
neighborhood.default = 0  
neighborhood.save!  
end  
@neighborhood.set\_as\_default  
@neighborhood.save!  
redirect\_to user\_user\_neighborhoods\_path(current\_user)  
end

is there a better way?

---

<div class="post-metadata">

**Author:** ![max](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e5b9ba/32.png) [@max](https://www.ruby-forum.com/u/max)\
**Post date:** [August 13, 2008, 9:22pm UTC](https://www.ruby-forum.com/t/is-there-a-better-way-to-do-this/145768/2 "2008-08-13T21:22:01Z")

</div>

I answered my own question… just FYI

```
def default
  @neighborhood = UserNeighborhood.find(params[:id])
  UserNeighborhood.update_all('user_neighborhoods.default = 0',

```

[‘user\_id = ?’,current\_user.id])  
@neighborhood.set\_as\_default  
@neighborhood.save!  
redirect\_to user\_user\_neighborhoods\_path(current\_user)  
end
