# Named\_scope lambda syntax

**URL:** <https://www.ruby-forum.com/t/named-scope-lambda-syntax/153872>\
**Category:** Rails\
**Created:** [November 22, 2008, 4:13am UTC](https://www.ruby-forum.com/t/named-scope-lambda-syntax/153872 "2008-11-22T04:13:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 22, 2008, 4:13am UTC](https://www.ruby-forum.com/t/named-scope-lambda-syntax/153872/1 "2008-11-22T04:13:11Z")

</div>

How would I pass an attribute name into a named\_scope lambda?

I want to be able to search an active record class for nil values in a  
particular attribute. Would like to use a named\_scope instead of find  
() because I want to tack other methods on the end of the result.  
Syntax I’ve tried:

# workouts table in mySQL:

# attributes time, reps, weight, distance

class Workout \< ActiveRecord::Base  
named\_scope :no\_score, lambda {|compare| {:conditions =\> ["? IS NULL",  
compare]}} # tried all these  
named\_scope :no\_score, lambda {|compare| {:conditions =\> {compare =\>  
nil }}} # forms of syntax  
named\_scope :no\_score, lambda {|compare| {:conditions =\>  
{compare.intern =\> nil }}} # with no success

WorkoutController  
@gym.workouts.no\_score(“time”)

Any ideas where I"m going wrong with the syntax?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 22, 2008, 5:26am UTC](https://www.ruby-forum.com/t/named-scope-lambda-syntax/153872/2 "2008-11-22T05:26:49Z")

</div>

never mind, I sorted it out. Solution:

named\_scope :no\_score, lambda { |compare| { :conditions =\> “#{compare}  
IS NULL” }}
