您好我有两个型号公司和Feed
company.rb
class Company < ActiveRecord::Base
attr_accessible :rss_url, :name
has_many :feeds
end
feed.rb
class Feed < ActiveRecord::Base
attr_accessible :guid, :name, :published_at, :summary, :url
after_create { |feed| FeedEntry.update_from_feed(feed.feed_url) }
belongs_to :company
def self.update_from_feed(rss_url) ?????
feed = Feedzirra::Feed.fetch_and_parse(rss_url) ?????
add_entries(feed.entries)
end
end
两个人如何从公司获取RSS_URL?
答案 0 :(得分:0)
我不知道add_entries
的作用,但如果您想访问rss_url
内的Feed
公司,则可以使用该关联。在Feed
类上定义此实例方法。
def do_something
url = self.company.rss_url
puts "This feed belongs to a company with the following rss url: #{url}"
end