Sha256: 22e7d8a63d46ed3fc3db86448855993f4bf5199c42f10612ed33ab77ad6a65e0
Contents?: true
Size: 1.43 KB
Versions: 5
Compression:
Stored size: 1.43 KB
Contents
require_dependency "pages_cms/application_controller" module PagesCms class Admin::ArticlesController < ApplicationController before_action :logged_in_admin def index @articles = Article.all filter_params(params).each do |search, result| @articles = @articles.public_send(search, result) if result.present? end end def new @article = Article.new end def create @article = Article.new(article_params) if @article.save flash[:success] = 'Successfully updated' redirect_to admin_articles_path else flash[:danger] = 'Failed to update' redirect_to admin_articles_path end end def edit @article = Article.find(params[:id]) end def update @article = Article.find(params[:id]) if @article.update(article_params) flash[:success] = 'Successfully updated' redirect_to admin_articles_path else flash[:danger] = 'Failed to update' redirect_to admin_articles_path end end def destroy Article.find(params[:id]).destroy flash[:success] = 'Destroyed article' redirect_to admin_articles_path end private def article_params params.require(:article).permit( :title, :tags, :content, :image_id, :draft, :archived ) end def filter_params(params) params.slice(:search, :status) end end end
Version data entries
5 entries across 5 versions & 1 rubygems