class MessagesController < ApplicationController
before_action :correct_user, only: [:index]
private
def correct_user
redirect_to root_path unless @conversation.sender_id == current_user.id || @conversation.receiver_id == current_user.id
end
end
scope :today, -> { where(:published_at.lt => 1.week.ago) }
def self.update_all_feeds(urls)
Feedjira::Feed.fetch_and_parse(urls,
:on_success => lambda { |url, feed|
rss = Source.only(:id).where(:url => url).first
Source.add_entries(feed.entries, rss.id)
}
)
end
task :collect => :environment do
urls = Source.only(:url).all.map { |v| v[:url] }
Source.update_all_feeds(urls)
end