I am new to Ruby and Ror so any guidance would be awesome. I have a function:
def self.insert_feed_product_scores(id, low, high)
avgScore = low.to_s + " - " + high.to_s
@feedProduct = FeedProduct.find(id)
@feedProduct.avg_score = avgScore
@feedProduct.save
end
If for some reason the id that I pass in isn’t found, I notice I get this error, thats fine:
ActiveRecord::RecordNotFound: Couldn't find FeedProduct with id=999999
I could write some logic and check if there is a score and there is something found before I save, but it just doesn’t seem like the Ruby way of doing things…should I just write in logic to validate or is there some Ruby/Ror way of doing things?
Thanks
If you want to track the error message and log properly, follow @lucapette answer. Else