Class: HelpKit::ArticlesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/help_kit/articles_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



30
31
32
33
34
35
36
37
# File 'app/controllers/help_kit/articles_controller.rb', line 30

def create
  @article = Article.new(article_params)
  if @article.save
    redirect_to @article
  else
    render 'new'
  end
end

#destroyObject



49
50
51
52
53
54
# File 'app/controllers/help_kit/articles_controller.rb', line 49

def destroy
  if @article.destroy
    flash[:success] = "Article deleted."
    redirect_to admin_landing_path
  end
end

#editObject



39
# File 'app/controllers/help_kit/articles_controller.rb', line 39

def edit; end

#index_categoryObject



15
16
17
18
# File 'app/controllers/help_kit/articles_controller.rb', line 15

def index_category
  @category = Category.friendly.find(params[:category])
  @articles = Article.published.for_category(@category)
end

#newObject



26
27
28
# File 'app/controllers/help_kit/articles_controller.rb', line 26

def new
  @article = Article.new(title: params[:title])
end

#publishObject



56
57
58
59
60
# File 'app/controllers/help_kit/articles_controller.rb', line 56

def publish
  @article.publish!
  flash[:success] = "Article published. It will now be viewable."
  redirect_to article_path(@article)
end

#searchObject



20
21
22
# File 'app/controllers/help_kit/articles_controller.rb', line 20

def search
  @articles = Article.search(params[:search][:query])
end

#showObject



24
# File 'app/controllers/help_kit/articles_controller.rb', line 24

def show; end

#unpublishObject



62
63
64
65
66
# File 'app/controllers/help_kit/articles_controller.rb', line 62

def unpublish
  @article.unpublish!
  flash[:success] = "Article unpublished. This article will no longer be visible"
  redirect_to article_path(@article)
end

#updateObject



41
42
43
44
45
46
47
# File 'app/controllers/help_kit/articles_controller.rb', line 41

def update
  if @article.update(article_params)
    redirect_to @article
  else
    render 'edit'
  end
end