Class: Legacy::NewsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Legacy::NewsController
- Defined in:
- app/controllers/legacy/news_controller.rb
Instance Method Summary collapse
-
#category ⇒ Object
get /news/:category_slug get /novosti/:category_slug.
-
#create ⇒ Object
post /news.
-
#destroy ⇒ Object
delete /news/:id.
-
#edit ⇒ Object
get /news/:id/edit.
-
#index ⇒ Object
get /news get /novosti.
-
#new ⇒ Object
get /news/new.
-
#show ⇒ Object
get /news/:id.
-
#show_in_category ⇒ Object
get /news/:category_slug/:slug get /novosti/:category_slug/:slug.
-
#update ⇒ Object
patch /news/:id.
Instance Method Details
#category ⇒ Object
get /news/:category_slug get /novosti/:category_slug
16 17 18 19 |
# File 'app/controllers/legacy/news_controller.rb', line 16 def category @category = NewsCategory.find_by! slug: params[:category_slug] @collection = News.of_type(:news).in_category(@category).page_for_visitors(current_page) end |
#create ⇒ Object
post /news
27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/legacy/news_controller.rb', line 27 def create @entity = News.new creation_parameters if @entity.save # add_figures unless params[:figures].blank? redirect_to admin_news_path(id: @entity.id) else render :new, status: :bad_request end end |
#destroy ⇒ Object
delete /news/:id
82 83 84 85 86 87 |
# File 'app/controllers/legacy/news_controller.rb', line 82 def destroy if @entity.update(deleted: true) flash[:notice] = t('news.destroy.success') end redirect_to admin_news_index_path end |
#edit ⇒ Object
get /news/:id/edit
68 69 |
# File 'app/controllers/legacy/news_controller.rb', line 68 def edit end |
#index ⇒ Object
get /news get /novosti
10 11 12 |
# File 'app/controllers/legacy/news_controller.rb', line 10 def index @collection = News.federal.page_for_visitors current_page end |
#new ⇒ Object
get /news/new
22 23 24 |
# File 'app/controllers/legacy/news_controller.rb', line 22 def new @entity = News.new end |
#show ⇒ Object
get /news/:id
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/legacy/news_controller.rb', line 38 def show @entity = News.find_by(id: params[:id], deleted: false) if @entity.nil? handle_http_404("Cannot find non-deleted news #{params[:id]}") else category_slug = @entity.news_category.slug if @entity.regional? redirect_to news_in_category_regional_news_index_path(category_slug: category_slug, slug: @entity.slug) else redirect_to news_in_category_news_index_path(category_slug: category_slug, slug: @entity.slug) end end end |
#show_in_category ⇒ Object
get /news/:category_slug/:slug get /novosti/:category_slug/:slug
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/legacy/news_controller.rb', line 54 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_news_index_path(parameters) end end |
#update ⇒ Object
patch /news/:id
72 73 74 75 76 77 78 79 |
# File 'app/controllers/legacy/news_controller.rb', line 72 def update if @entity.update entity_parameters # add_figures unless params[:figures].blank? redirect_to admin_news_path(id: @entity.id), notice: t('news.update.success') else render :edit, status: :bad_request end end |