This should be a class method with a prefix self.:
def self.check_status(posts)
posts.each do |post|
end
end
Then you call it like this:
Post.check_status(@posts)
-
You can also do something like this:
def check_status
self.status == 'published'
end
Then you can call it in separate instances Post, for example:
@posts = Post.all
@post.each do |post|
if post.check_status
end
end
source
share