Class: Admin::ArticlesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/pages_cms/admin/articles_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/pages_cms/admin/articles_controller.rb', line 21

def create
  return_articles
  @article = .articles.build(article_params)
  if @article.save
    flash[:success] = 'Successfully updated'
    redirect_to admin_articles_path
  else
    @new = true
    flash[:danger] = "Failed: #{@article.errors.full_messages.to_sentence}"
    render :index
  end
end

#destroyObject



48
49
50
51
52
# File 'app/controllers/pages_cms/admin/articles_controller.rb', line 48

def destroy
  Article.find(params[:id]).destroy
  flash[:success] = 'Destroyed article'
  redirect_to admin_articles_path
end

#indexObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/pages_cms/admin/articles_controller.rb', line 8

def index
  return_articles
  if params[:edit].present? && Article.exists?(params[:edit])
    @article = Article.find(params[:edit])
    @edit = true
  elsif params[:new] == 'true'
    @article = Article.new
    @new = true
  else
    @article = false
  end
end

#updateObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/pages_cms/admin/articles_controller.rb', line 34

def update
  return_articles
  @article = Article.find(params[:id])
  if @article.update(article_params)
    @edit = true
    flash[:success] = 'Successfully updated'
    render :index
  else
    @edit = true
    flash[:danger] = "Failed: #{@article.errors.full_messages.to_sentence}"
    render :index
  end
end