Sha256: 189895367a3c1663a341e2ff6fade0fbe3e5f373a10fd53859eecc20cbb7cf65
Contents?: true
Size: 1.94 KB
Versions: 10
Compression:
Stored size: 1.94 KB
Contents
class Admin::PostsController < ApplicationController include ActionControllerMixin before_filter :authenticate_user! if Object.const_defined?('Devise') before_filter :scope_blog before_filter :scope_post, :only => [:destroy, :edit, :show, :update] # CRUD =========================================================================================== def index params[:labels] = { :humanize_path => 'URL', :state => 'Status', :updated_at => 'Last Modified' } params[:by] ||= 'humanize_path'; params[:dir] ||= 'ASC' @posts = @blog.posts.sort{|a,b| a.send(params[:by]) <=> b.send(params[:by])} @posts.reverse! if params[:dir] == 'DESC' end def show end def new @post = @blog.posts.build end def create handle_date_time params, :post, :publication_date @post = @blog.posts.build params[:post] if @post.save @post.publish! if params[:commit] == 'Publish' || params[:post][:state] == 'published' flash[:notice] = 'Successfully created post.' redirect_to admin_blog_post_path(@blog, @post) else render :action => 'new' end end def edit end def update handle_date_time params, :post, :publication_date if params[:commit] == 'Preview' @post = @blog.posts.new params[:post] render :action => 'preview', :layout => 'application' else if @post.update_attributes params[:post] @post.publish! if params[:commit] == "Publish" @post.unpublish! if params[:commit] == "Save as Draft" flash[:notice] = 'Successfully updated post.' redirect_to admin_blog_post_path(@blog, @post) else render :action => 'edit' end end end def destroy @post.destroy flash[:notice] = 'Successfully destroyed post.' redirect_to admin_blog_posts_url(@blog) end private def scope_blog @blog = Blog.first end def scope_post @post = @blog.posts.find params[:id] end end
Version data entries
10 entries across 10 versions & 1 rubygems