# Variables in find

**URL:** <https://www.ruby-forum.com/t/variables-in-find/117679>\
**Category:** Rails\
**Created:** [October 19, 2007, 10:04am UTC](https://www.ruby-forum.com/t/variables-in-find/117679 "2007-10-19T10:04:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gorter9](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/839c29/32.png) [@gorter9](https://www.ruby-forum.com/u/gorter9)\
**Post date:** [October 19, 2007, 10:04am UTC](https://www.ruby-forum.com/t/variables-in-find/117679/1 "2007-10-19T10:04:07Z")

</div>

How can i make a variable in find my code is

@gardens = Garden.find(:all, :conditions =\> { :user\_id =\> 1})

The number 1 must be a variable of user.id so you only get the stuff  
placed by the user logged in at the moment

---

<div class="post-metadata">

**Author:** ![gorter9](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/839c29/32.png) [@gorter9](https://www.ruby-forum.com/u/gorter9)\
**Post date:** [October 19, 2007, 10:11am UTC](https://www.ruby-forum.com/t/variables-in-find/117679/2 "2007-10-19T10:11:11Z")

</div>

On 19 Oct 2007, at 09:04, GA Gorter wrote:

> How can i make a variable in find my code is
> 
> @gardens = Garden.find(:all, :conditions =\> { :user\_id =\> 1})
> 
> The number 1 must be a variable of user.id so you only get the stuff  
> placed by the user logged in at the moment

Not sure I get the question. What’s wrong with?  
@gardens = Garden.find(:all, :conditions =\> { :user\_id =\> user.id})

Ideally user would has\_many :gardens, then you can just do  
@gardens = user.gardens.

Fred
