New to rails….still trying to grasp all the “methods”
Table is called Histories.
@compa = History.scoped(:limit => 10,:conditions => {:name => "IBM"}, :order => "closedate ASC")
Now I want to find if that @compa subset of the table contains an entry where the closedate = a specific date. I’ve tried all sorts of methods, but nothing seems to work.
Example:
if (@compa.has_value?(tmp))
Doesn’t work.
Should I work in the subset, or go back to the table and do a new scope? How can I work in the subset…I’m missing something I’m sure.
So you would want something like:
To see if @compa has the value,
tmp.However
@compacontains attributes other than closedate. So you would want:This will return nil if it doesn’t contain that value, otherwise it will return the object that does have
closedateequal totmp.However why not use SQL to handle this:
Since
@compais an ActiveRecord Relation(because you called scoped), you can query it more by doing something like:Links:
Array#include
Enumerable#find
exists?