Class: Legacy::PostsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Legacy::PostsController
- Defined in:
- app/controllers/legacy/posts_controller.rb
Instance Method Summary collapse
-
#archive ⇒ Object
get /posts/archive/(:year)/(:month).
-
#category ⇒ Object
get /posts/:category_slug.
-
#create ⇒ Object
post /posts.
-
#destroy ⇒ Object
delete /posts/:id.
-
#edit ⇒ Object
get /posts/:id/edit.
-
#index ⇒ Object
get /posts.
-
#new ⇒ Object
get /posts/new.
-
#show ⇒ Object
get /posts/:id.
-
#show_in_category ⇒ Object
get /posts/:category_slug/:slug get /publikacii/:category_slug/:slug.
-
#update ⇒ Object
patch /posts/:id.
Instance Method Details
#archive ⇒ Object
get /posts/archive/(:year)/(:month)
83 84 85 86 |
# File 'app/controllers/legacy/posts_controller.rb', line 83 def archive collect_months @collection = Post.archive(params[:year], params[:month]).page_for_visitors current_page unless params[:month].nil? end |
#category ⇒ Object
get /posts/:category_slug
14 15 16 17 |
# File 'app/controllers/legacy/posts_controller.rb', line 14 def category @category = PostCategory.find_by! slug: params[:category_slug] @collection = Post.in_category(@category).page_for_visitors(current_page) end |
#create ⇒ Object
post /posts
25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/legacy/posts_controller.rb', line 25 def create @entity = Post.new creation_parameters if @entity.save # set_dependent_entities redirect_to admin_post_path(id: @entity.id) else render :new, status: :bad_request end end |
#destroy ⇒ Object
delete /posts/:id
75 76 77 78 79 80 |
# File 'app/controllers/legacy/posts_controller.rb', line 75 def destroy if @entity.update(deleted: true) flash[:notice] = t('posts.destroy.success') end redirect_to admin_posts_path end |
#edit ⇒ Object
get /posts/:id/edit
61 62 |
# File 'app/controllers/legacy/posts_controller.rb', line 61 def edit end |
#index ⇒ Object
get /posts
9 10 11 |
# File 'app/controllers/legacy/posts_controller.rb', line 9 def index @collection = Post.page_for_visitors current_page end |
#new ⇒ Object
get /posts/new
20 21 22 |
# File 'app/controllers/legacy/posts_controller.rb', line 20 def new @entity = Post.new end |
#show ⇒ Object
get /posts/:id
36 37 38 39 40 41 42 43 |
# File 'app/controllers/legacy/posts_controller.rb', line 36 def show @entity = Post.find_by(id: params[:id], deleted: false) if @entity.nil? handle_http_404("Cannot find non-deleted post #{params[:id]}") else redirect_to post_in_category_posts_path(category_slug: @entity.post_category.slug, slug: @entity.slug) end end |
#show_in_category ⇒ Object
get /posts/:category_slug/:slug get /publikacii/:category_slug/:slug
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/legacy/posts_controller.rb', line 47 def show_in_category @category = PostCategory.find_by(slug: params[:category_slug], deleted: false) @entity = Post.find_by(slug: params[:slug], deleted: false) if @entity.nil? || !@entity.visible_to?(current_user) handle_http_404("Cannot show post #{params[:slug]} to user #{current_user&.id}") elsif @entity.post_category == @category @entity.increment! :view_count else parameters = { category_slug: @entity.post_category.slug, slug: @entity.slug } redirect_to post_in_category_posts_path(parameters) end end |
#update ⇒ Object
patch /posts/:id
65 66 67 68 69 70 71 72 |
# File 'app/controllers/legacy/posts_controller.rb', line 65 def update if @entity.update entity_parameters # set_dependent_entities redirect_to admin_post_path(id: @entity.id), notice: t('posts.update.success') else render :edit, status: :bad_request end end |