Sha256: 08543f5a8109eee43cb94c7127392a4c6d9d123a0466f891d5f432150b8afef7

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

class Admin::Blog::BlogsController < Admin::Blog::BaseController
  
  before_action :build_blog,  :only => [:new, :create]
  before_action :load_blog,   :only => [:edit, :update, :destroy]
  
  def index
    @blogs = @site.blogs.page(params[:page])
  end
  
  def new
    render
  end
  
  def edit
    render
  end

  def create
    @blog.save!
    flash[:success] = 'Blog created'
    redirect_to :action => :edit, :id => @blog
  rescue ActiveRecord::RecordInvalid
    flash.now[:error] = 'Failed to create Blog'
    render :action => :new
  end

  def update
    @blog.update_attributes!(blog_params)
    flash[:success] = 'Blog updated'
    redirect_to :action => :edit, :id => @blog
  rescue ActiveRecord::RecordInvalid
    flash.now[:error] = 'Failed to update Blog'
    render :action => :edit
  end

  def destroy
    @blog.destroy
    flash[:success] = 'Blog deleted'
    redirect_to :action => :index
  end

protected
  
  def build_blog
    @blog = @site.blogs.new(blog_params)
  end
  
  def blog_params
    params.fetch(:blog, {}).permit!
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
comfy_blog-1.1.1 app/controllers/admin/blog/blogs_controller.rb
comfy_blog-1.1.0 app/controllers/admin/blog/blogs_controller.rb
comfy_blog-1.0.0 app/controllers/admin/blog/blogs_controller.rb