Class: HelpKit::ArticlesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- HelpKit::ArticlesController
- Defined in:
- app/controllers/help_kit/articles_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index_category ⇒ Object
- #new ⇒ Object
- #publish ⇒ Object
- #search ⇒ Object
- #show ⇒ Object
- #unpublish ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
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 |
#destroy ⇒ Object
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 |
#edit ⇒ Object
39 |
# File 'app/controllers/help_kit/articles_controller.rb', line 39 def edit; end |
#index_category ⇒ Object
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 |
#new ⇒ Object
26 27 28 |
# File 'app/controllers/help_kit/articles_controller.rb', line 26 def new @article = Article.new(title: params[:title]) end |
#publish ⇒ Object
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 |
#search ⇒ Object
20 21 22 |
# File 'app/controllers/help_kit/articles_controller.rb', line 20 def search @articles = Article.search(params[:search][:query]) end |
#show ⇒ Object
24 |
# File 'app/controllers/help_kit/articles_controller.rb', line 24 def show; end |
#unpublish ⇒ Object
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 |
#update ⇒ Object
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 |