Sunday, April 25, 2010

[Rails] a method to search for empty stuff

I'm trying to write some tools to help me clean up my data, first stop
is trying to find empty attributes in my Resort model...the following
works,

def self.find_empty_resort_heights
resorts = []
Resort.all.each do |resort|
if resort.TopLiftHeight.nil?
puts resort.name + "has no height entered"
end
end
end


I'm not using the array in this example, but it gives an idea. I'd like
to rewrite this so that I pass in an attribute name and it gives me back
the resorts where that attribute name is nil or whatever. I can't seem
to do it, I thought it'd start like this..

def self.find_empty_things(name_of_attrib)

code to do it


How do I write that first line so I can pass in an attribute?

bb
--
Posted via http://www.ruby-forum.com/.

--
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@googlegroups.com.
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate