Topic: Class scope question
I hope this the right place. My question is more ruby than rails. When I am writing models sometimes it is nessisary for me to use self and other times I don't need to. I was hoping some one could enlighten me on the subtleties that I am not seeing. They seem the same to me. Let me give you an example.This is a method in one of my models
def fetch_articles
current_feed = get_rss_feed( 5 )
debugger
if current_feed.class == Feedzirra::Parser::RSS
self.status = true
else
self.status = false
end
self.save
if status
current_feed.entries.each do |article|
unless Article.array_of_article_urls.include?(article.url)
a = Article.new(title: article.title, content: article.content, source: article.url, clicks: 0)
a.title ||= article.summary
a.content ||= article.summary
a.save
end
end
end
endBefore I didn't have those self's it wouldn't persist the changes in the database then when I added them it worked.yet a little later this one works fine without self.
def display_status
if status
"<span class='label label-success'>Success</span>"
else
"<span class='label label-important'>Fail</span>"
end
end Last edited by tyger86 (2012-10-03 17:30:40)