# Ez\_where : i'm puzzled

**URL:** <https://www.ruby-forum.com/t/ez-where-im-puzzled/93945>\
**Category:** Rails\
**Created:** [April 15, 2006, 7:50pm UTC](https://www.ruby-forum.com/t/ez-where-im-puzzled/93945 "2006-04-15T19:50:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [April 15, 2006, 7:50pm UTC](https://www.ruby-forum.com/t/ez-where-im-puzzled/93945/1 "2006-04-15T19:50:22Z")

</div>

I have the following code:

```
condition_clause = "%#{@phrase}%"
logger.info "condition is #{condition_clause}"
unless @phrase.nil?
  condition = Caboose::EZ::Condition.new :affiliates do
    affiliate_name =~ "%#{@phrase}%" # <<< here's the problem
  end
  options[:conditions] = condition.to_sql
  logger.info "ajax param is #{@phrase}"
  logger.info "ez condition is #{condition.to_sql}"
end

```

The output from the logs is:

ajax param is map  
ez condition is

In other words, the the where clause is not being constructed. However,  
if I  
change the line marked above to:

affiliate\_name =~ condition\_clause # \<\<\< here’s the fix

Everything works. I’ve ascertained that by the time I’m in operator=~,  
all  
that’s left is ‘%%’.

Is there something obvious I’ve missed about this straightforward  
variable  
interpolation?

TIA

–  
View this message in context:  
[http://www.nabble.com/ez\_where-%3A-i'm-puzzled-t1455038.html#a3932303](http://www.nabble.com/ez_where-%3A-i%27m-puzzled-t1455038.html#a3932303)  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [April 15, 2006, 10:27pm UTC](https://www.ruby-forum.com/t/ez-where-im-puzzled/93945/2 "2006-04-15T22:27:31Z")

</div>

s.ross-

```
Yeah I see what the problem is. I need to add a bit to the

```

documentation to clarify this. The problem is that inside the  
Condition.new block, self is another object internal to the ez\_where  
plugin. So instance variables with the @ sign are not set because  
they are instance variables and you are inside another instance  
inside that block. If you make @phrase a local variable by changing  
it to phrase without the @ sign it will work properly.

Cheers-  
-Ezra

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [April 15, 2006, 10:30pm UTC](https://www.ruby-forum.com/t/ez-where-im-puzzled/93945/3 "2006-04-15T22:30:40Z")

</div>

Thanks so much. That explains the behavior.

## –steve

View this message in context:  
[http://www.nabble.com/ez\_where-%3A-i'm-puzzled-t1455038.html#a3933836](http://www.nabble.com/ez_where-%3A-i%27m-puzzled-t1455038.html#a3933836)  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).
