Class: PageUrl

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

Constant Summary collapse

@@per_page =
10

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.update(page) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/page_url.rb', line 19

def self.update(page)
  pu = PageUrl.where(:page_id=>page.id).where(:page_type=>page.class.name.tableize).first
  
  pu ||= PageUrl.new(:page_id=>page.id, :page_type=>page.class.name.tableize)
  pu.full_path = page.full_path
  pu.name = page.name
  pu.title = page.title
  pu.category_id = page.category_id
  pu.status_id = page.status_id
  pu.tags = page.tags
  pu.save
end

Instance Method Details

#is_favourite?(current_user) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/models/page_url.rb', line 40

def is_favourite?(current_user)
  current_user.is_favourite_page?(self)
end


32
33
34
35
36
37
38
# File 'app/models/page_url.rb', line 32

def link(mode='show', inplace_edit=false)
  if mode=='show'
    return self.full_path + (inplace_edit ? "?edit=1" : "")
  else
    return "/#{self.page_type}/#{self.page_id}/#{mode}"
  end
end

#recent_threads(count, user) ⇒ Object



13
14
15
16
17
# File 'app/models/page_url.rb', line 13

def recent_threads(count, user)
  level = user ? user.forum_level : 0

  self.topic_threads.limit(count).order("topic_threads.id desc").includes(:topic).where("topic_threads.is_visible = 1 and topics.is_visible = 1 and topics.read_access_level <= #{level}")
end