Class: Blog

Inherits:
Object
  • Object
show all
Includes:
ContentItem
Defined in:
app/models/blog.rb

Overview

A Blog is a collection of Postings which may or may not references a ‘ContentItem’ (eg Page). When a Blog references a Page, the Page sould be seen as the ‘Intro’ to this blog.

Instance Method Summary (collapse)

Methods included from ContentItem

included, #markdown, #normalized_tags_with_weight

Instance Method Details

- (Object) create_posting(form_params, current_user)

Create a posting with attachments from params for current_user



44
45
46
47
48
49
50
51
# File 'app/models/blog.rb', line 44

def create_posting(form_params,current_user)
  posting = self.postings.create(form_params)
  posting.user = current_user
  if posting.save && self.save
    posting.attachments.each(&:save) if posting.attachments
  end
  posting
end

- (Object) page_tokens=(tokens)

page_tokens are page::object_ids of the pages which should be displayed on the sidebar of this blog.



37
38
39
40
41
# File 'app/models/blog.rb', line 37

def page_tokens=(tokens)
  @pages_before = self.pages.unscoped
  self.pages.nullify
  self.pages.push(Page.criteria.for_ids(tokens).all)
end

- (Boolean) public?

True if user_role is not defined or eql 0

Returns:

  • (Boolean)

    true if user_role is not defined or eql 0



71
72
73
# File 'app/models/blog.rb', line 71

def public?
  self.user_role == nil || self.user_role == 0
end

- (Criteria) scoped_pages(options = nil)

find pages with filter

Parameters:

  • options (Hash) (defaults to: nil)

    a filter to find pages of this blog e.g. ’{ is_draft: true }’

Returns:

  • (Criteria)

    Criteria on self.pages.where( options )



65
66
67
68
# File 'app/models/blog.rb', line 65

def scoped_pages(options=nil)
  return self.pages unless options
  self.pages.where( options )
end

- (Criteria) scoped_postings(options = nil)

find postings with filter

Parameters:

  • options (Hash) (defaults to: nil)

    a filter to find postings of this blog e.g. ’{ is_draft: true }’

Returns:

  • (Criteria)

    Criteria on self.postings.where( options )



57
58
59
60
# File 'app/models/blog.rb', line 57

def scoped_postings(options=nil)
  return self.postings unless options
  self.postings.unscoped.where( options )
end