Class: EricWeixin::News

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/eric_weixin/news.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_news_datas(options, weixin_article_data_ids, weixin_article_data_sort) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/eric_weixin/news.rb', line 18

def create_news_datas(options, weixin_article_data_ids, weixin_article_data_sort)
  ::EricWeixin::News.transaction do
    news_data = ::EricWeixin::News.new
    news_data.update_attributes(options)
    news_data.weixin_articles.clear
    weixin_article_data_ids.each do |article_data_id|
      article_data = ::EricWeixin::Article.find(article_data_id)
      if (!article_data.blank?) && (!news_data.weixin_articles.include?(article_data))
        ::EricWeixin::ArticleNews.create! weixin_article_id: article_data_id, weixin_news_id: news_data.id, sort: weixin_article_data_sort[article_data_id].first
      end
    end
    news_data.save!
    news_data
  end
end

.update_news_datas(id, options, weixin_article_data_ids, weixin_article_data_sort) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/eric_weixin/news.rb', line 35

def update_news_datas(id, options, weixin_article_data_ids, weixin_article_data_sort)
  ::EricWeixin::News.transaction do
    news_data = ::EricWeixin::News.find(id)
    news_data.update(options)
    news_data.weixin_articles.clear
    weixin_article_data_ids.each do |article_data_id|
      article_data = ::EricWeixin::Article.find(article_data_id)
      if (!article_data.blank?) && (!news_data.weixin_articles.include?(article_data))
        ::EricWeixin::ArticleNews.create! weixin_article_id: article_data_id, weixin_news_id: news_data.id, sort: weixin_article_data_sort[article_data_id].first
      end
    end
    news_data.save!
    news_data
  end

end

Instance Method Details

#generate_news_dataObject



8
9
10
11
12
13
14
15
# File 'app/models/eric_weixin/news.rb', line 8

def generate_news_data
  articles = []
  self.weixin_articles.each do |article_data|
    article = generate_article(article_data.title, article_data.desc, article_data.pic_url, article_data.link_url)
    articles << article
  end
  articles
end