never mind, I sorted it out. Solution:
named_scope :no_score, lambda { |compare| { :conditions => "#{compare}
IS NULL" }}
On Nov 21, 10:12 pm, Ed
<haywood...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---