So I’ve got an application which simply takes a number of RSS feeds and stores them in a table. It checks a couple of things in each entry for conditions and then sets an attribute based on the condition.
if self.value1 > self.value2 then
:status => 'foo'
else
:status => 'bar'
end
I’m still a bit of a noob with Ruby/Rails and setting the status is causing an exception but I don’t know why.
Any help would be great.
When you say “sets an attribute”, I assume that you mean this is another column on the table. If so, this should work:
The “rocket” notation (
:this => "that") is used when instantiating an object, or when updating more than one attribute (self.update_attributes :animal => "kitten", :sound => "Roar!"). It’s the notation that a Hash uses.You could also just use
status = "foo", but that will set the attribute without saving, so you’d also have to callself.save.update_attributedoes both in one neat package.