Class: Dokno::ArticlesController
Instance Method Summary
collapse
#paginate
#authorize, #can_edit?, #sanitized_user_obj_string, #user, #username
Instance Method Details
#create ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'app/controllers/dokno/articles_controller.rb', line 37
def create
@article = Article.new(article_params)
set_editor_username
if @article.save
flash[:green] = 'Article was created'
@article.categories = Category.where(code: params[:category_code]) if params[:category_code].present?
redirect_to article_path @article.slug
else
flash.now[:red] = 'Article could not be created'
@category_codes = params[:category_code]
render :new
end
end
|
#destroy ⇒ Object
71
72
73
74
75
76
|
# File 'app/controllers/dokno/articles_controller.rb', line 71
def destroy
Article.find(params[:id].to_i).destroy!
flash[:green] = 'Article was deleted'
render json: {}, layout: false
end
|
#edit ⇒ Object
32
33
34
35
|
# File 'app/controllers/dokno/articles_controller.rb', line 32
def edit
return redirect_to root_path if @article.blank?
@category_codes = @article.categories.pluck(:code)
end
|
#new ⇒ Object
26
27
28
29
30
|
# File 'app/controllers/dokno/articles_controller.rb', line 26
def new
@article = Article.new
@template = Article.template
@category_codes = [] << params[:category_code]
end
|
#panel ⇒ Object
Ajax-fetched slide-in article panel for the host app
79
80
81
|
# File 'app/controllers/dokno/articles_controller.rb', line 79
def panel
render json: @article&.host_panel_hash, layout: false
end
|
#preview ⇒ Object
Ajax-fetched preview of article content from article form
84
85
86
87
|
# File 'app/controllers/dokno/articles_controller.rb', line 84
def preview
content = Article.parse_markdown params['markdown']
render json: { parsed_content: content.presence || 'Nothing to preview' }, layout: false
end
|
#show ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/controllers/dokno/articles_controller.rb', line 9
def show
redirect_to root_path if @article.blank?
@search_term = params[:search_term]
@order = params[:order]
@category = Category.find_by(code: params[:cat_code].to_s.strip) if params[:cat_code].present?
@category = @article.categories.first if @category.blank?
if !@article.active
flash.now[:yellow] = 'This article is no longer active'
elsif @article.up_for_review?
flash_msg = @article.review_due_days_string
flash_msg += " - <a href='#{edit_article_path(@article.slug)}' class='font-bold'>review it now</a>" if can_edit?
flash.now[:gray] = flash_msg
end
end
|
#status ⇒ Object
Ajax-invoked article status changing
90
91
92
93
94
|
# File 'app/controllers/dokno/articles_controller.rb', line 90
def status
set_editor_username
@article.update!(active: params[:active])
render json: {}, layout: false
end
|
#update ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'app/controllers/dokno/articles_controller.rb', line 52
def update
@article = Article.find_by(id: params[:id].to_i)
return redirect_to root_path if @article.blank?
set_editor_username
if @article.update(article_params)
flash[:green] = 'Article was updated'
@article.categories = Category.where(code: params[:category_code])
redirect_to article_path @article.slug
else
flash.now[:red] = 'Article could not be updated'
@category_codes = params[:category_code]
@reset_review_date = params[:reset_review_date]
@review_notes = params[:review_notes]
render :edit
end
end
|