0

嗨,我有两个模型公司和饲料

公司.rb

class Company < ActiveRecord::Base
  attr_accessible :rss_url, :name
  has_many :feeds
end

饲料.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 到 feed ?

4

1 回答 1

0

我不知道有什么add_entries作用,但是如果你想访问rss_urlCompany inside Feed,你可以使用关联。Feed在您的类上定义此实例方法。

def do_something
  url = self.company.rss_url
  puts "This feed belongs to a company with the following rss url: #{url}"
end
于 2013-05-13T14:16:24.967 回答