我有一个在两个域上运行的 Rails 应用程序,domain1并且domain2. 每个域都有自己的关联博客,domain1blog和domain2blog,分别。目前,我有一个模型可以获取其中一个博客:
require 'rss'
require 'open-uri'
class Blog
BLOG_URL = 'http://feeds.feedburner.com/domain1blog?format=xml'
POST_LIMIT = 2
def self.fetch_entries
Rails.cache.fetch('blog', expires_in: 10.minutes) do
posts = []
begin
open BLOG_URL do |rss|
feed = RSS::Parser.parse(rss)
posts = feed.items.slice 0...POST_LIMIT
end
rescue OpenURI::HTTPError
# Ignore silently.
end
posts
end
end
end
现在,domain1blog无论从哪个域进行调用,此模型都会从其中获取内容。
如何设置BLOG_URL它以使其指向domain1blogfromdomain1和domain2blogfrom domain2?