Class: Legacy::PostsController

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

Instance Method Summary collapse

Instance Method Details

#archiveObject

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

#categoryObject

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

#createObject

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

#destroyObject

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

#editObject

get /posts/:id/edit



61
62
# File 'app/controllers/legacy/posts_controller.rb', line 61

def edit
end

#indexObject

get /posts



9
10
11
# File 'app/controllers/legacy/posts_controller.rb', line 9

def index
  @collection = Post.page_for_visitors current_page
end

#newObject

get /posts/new



20
21
22
# File 'app/controllers/legacy/posts_controller.rb', line 20

def new
  @entity = Post.new
end

#showObject

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..slug, slug: @entity.slug)
  end
end

#show_in_categoryObject

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. == @category
    @entity.increment! :view_count
  else
    parameters = { category_slug: @entity..slug, slug: @entity.slug }
    redirect_to post_in_category_posts_path(parameters)
  end
end

#updateObject

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