Class: RegionalNewsController

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

Instance Method Summary collapse

Instance Method Details

#categoryObject

get /regional_news/:category_slug



8
9
10
11
# File 'app/controllers/regional_news_controller.rb', line 8

def category
  @category   = NewsCategory.find_by! slug: params[:category_slug]
  @collection = News.of_type(:news).in_category(@category).page_for_visitors(current_page)
end

#indexObject

get /regional_news



3
4
5
# File 'app/controllers/regional_news_controller.rb', line 3

def index
  @collection = News.regional.page_for_visitors current_page
end

#show_in_categoryObject

get /regional_news/:category_slug/:slug



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/regional_news_controller.rb', line 14

def show_in_category
  @category = NewsCategory.find_by(slug: params[:category_slug])
  @entity   = News.find_by(slug: params[:slug], deleted: false)
  if @entity.nil? || !@entity.visible_to?(current_user)
    handle_http_404("Cannot show news #{params[:slug]} to user #{current_user&.id}")
  elsif @entity.news_category == @category
    @entity.increment! :view_count
  else
    parameters = { category_slug: @entity.news_category.slug, slug: @entity.slug }
    redirect_to news_in_category_regional_news_index_path(parameters)
  end
end