Class: NewsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/news_controller.rb

Overview

Displaying news for visitors

Instance Method Summary collapse

Instance Method Details

#categoryObject

get /news/:category_slug



19
20
21
22
23
24
25
# File 'app/controllers/news_controller.rb', line 19

def category
  @collection = Post.in_category_branch(@category).for_language(current_language).page_for_visitors(current_page)
  respond_to do |format|
    format.html
    format.json { render('posts/index') }
  end
end

#indexObject

get /news



9
10
11
12
13
14
15
16
# File 'app/controllers/news_controller.rb', line 9

def index
  post_type = PostType.find_by(slug: 'news')
  @collection = post_type.posts.page_for_visitors(current_page)
  respond_to do |format|
    format.html
    format.json { render('posts/index') }
  end
end

#showObject

get /news/:post_id-:post_slug



28
29
30
31
32
# File 'app/controllers/news_controller.rb', line 28

def show
  @entity.increment :view_count
  @entity.increment :rating, 0.0025
  @entity.save
end

#show_in_categoryObject

get /news/:category_slug/:slug



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/news_controller.rb', line 35

def show_in_category
  post_type = PostType.find_by(slug: 'news')
  @entity = post_type.posts.list_for_visitors.find_by(slug: params[:slug])
  if @entity.nil?
    handle_http_404('Cannot find news')
  else
    @entity.increment :view_count
    @entity.increment :rating, 0.0025
    @entity.save

    render :show
  end
end

#taggedObject

get /news/tagged/:tag_name



50
51
52
53
# File 'app/controllers/news_controller.rb', line 50

def tagged
  post_type = PostType.find_by(slug: 'news')
  @collection = post_type.posts.tagged(params[:tag_name]).page_for_visitors(current_page)
end