2
我正在使用Feedzirra,並試圖根據發佈日期對源數據進行哈希排序。我沒有收到任何錯誤,只是沒有排序。以下是我的控制器中的代碼:Feedzirra和哈希分類
class ClassifiedsController < ApplicationController
def index
require 'feedzirra'
feed_urls = ["http://newjersey.craigslist.org/jjj/index.rss", "http://cnj.craigslist.org/jjj/index.rss"]
feeds = Feedzirra::Feed.fetch_and_parse(feed_urls)
x = 1
@items = Hash.new
feeds.each do |feed_url, feed|
feed.entries.each do |entry|
@items[x] = {:title => entry.title, :url => entry.url,
:published => entry.published.to_i}
x = x + 1
end
end
@items.sort_by { |k, v| v[:published] }
end
end
任何幫助將不勝感激。謝謝!
這裏看一看:[誘騙排序在紅寶石哈希(http://stackoverflow.com/a/12833824/2312749) – Pol0nium