Sha256: 66a0c89081b05b2e2dabdd7ad342b92eb27fb6a70afe8fa4b10744590bf9b4e1
Contents?: true
Size: 1.83 KB
Versions: 1
Compression:
Stored size: 1.83 KB
Contents
module Blogo::Admin # Responsible for posts management: creation, editing, deletion, preview. class PostsController < BaseController # GET /admin/posts # def index @posts = Blogo::Post.all end # GET /admin/posts/new # def new @post = Blogo::Post.new(published: true) end # POST /admin/posts # def create service = Blogo::CreatePostService.new(blogo_current_user, post_params) if service.create! @post = service.post flash[:notice] = "The post is created" redirect_to blogo_admin_posts_path else @post = service.post render 'new' end end # GET /admin/posts/:id/edit # def edit @post = Blogo::Post.where(permalink: params[:id]).first! end # PATCH /admin/posts/:id # def update @post = Blogo::Post.where(permalink: params[:id]).first! service = Blogo::UpdatePostService.new(@post, post_params) if service.update! flash[:notice] = "The post is updated" redirect_to blogo_admin_posts_path else render 'edit' end end # DELETE /admin/posts/:id # def destroy post = Blogo::Post.find(params[:id]) Blogo::DestroyPostService.new(post).destroy! flash[:notice] = "The post is removed" redirect_to blogo_admin_posts_path end # POST /admin/posts/preview # def preview @post = Blogo::PreviewPostService.new(blogo_current_user, post_params).preview @meta = {title: @post.title } @tags = Blogo::Tag.all render 'blogo/posts/show', layout: 'blogo/blog' end private # Get post parameters from params. # # @return [Hash] def post_params params.require(:post).permit(:title, :permalink, :published_at, :raw_content, :published, :tags_string) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
blogo-0.0.7 | app/controllers/blogo/admin/posts_controller.rb |