[Rails] Re: [ANN] Where Plugin

Ezra Zygmuntowicz ezra at yakima-herald.com
Tue Jan 3 18:10:31 GMT 2006


On Jan 3, 2006, at 1:31 AM, Jens-Christian Fischer wrote:

> I just found a problem that I'm not sure how to solve:
>
> Converting this:
>
> Task.find(:all, :conditions => ['project_id = ?', self.id] )
>
> to
>
> Task.find_with_conditions(:all) do
>   project_id '=', self.id
> end
>
> breaks horrible, because "self.id" in the block references god  
> knows what (probably the Cond block) instead of the ActiveRecord  
> object. A work around is to use a temporary variable:
>
> id = self.id
> Task.find_with_conditions(:all) do
>   project_id '=', id
> end
>
> Hmm - not that nice. Any ideas on how to solve that?
>
> jc


Jens-

	I think that I know a way around it. If you wrap it like "# 
{self.id}"  , I think it will get evaluated before self refers to the  
Cond class inside the block.	Can you try it and confirm that this works?


> Task.find_with_conditions(:all) do
>   project_id '=', "#{self.id}"
> end

Thanks-

-Ezra Zygmuntowicz
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
ezra at yakima-herald.com





More information about the Rails mailing list