app/controllers/storytime/dashboard/posts_controller.rb in storytime-2.0.0 vs app/controllers/storytime/dashboard/posts_controller.rb in storytime-2.1.0

- old
+ new

@@ -1,15 +1,15 @@ -require_dependency "storytime/application_controller" +require_dependency "storytime/dashboard_controller" module Storytime module Dashboard class PostsController < DashboardController before_action :hide_nav, only: [:new, :create, :edit, :update] before_action :set_post, only: [:edit, :update, :destroy] before_action :load_posts, only: :index before_action :load_media, only: [:new, :edit] - + respond_to :json, only: :destroy respond_to :html, only: :destroy set_tab :blog_posts @@ -54,11 +54,11 @@ end def update authorize @post @post.draft_user_id = current_user.id - + if @post.update_attributes(post_params) @post.autosave.destroy unless @post.autosave.nil? send_subscriber_notifications if @post.published? && post_params[:notifications_enabled] == "1" @@ -71,11 +71,11 @@ def destroy authorize @post @post.destroy flash[:notice] = I18n.t('flash.posts.destroy.success') unless request.xhr? - + respond_with [:dashboard, @post] do |format| format.html{ redirect_to [:dashboard, current_post_type], type: @post.type_name } end end @@ -87,11 +87,13 @@ def load_posts @blog = Blog.friendly.find(params[:blog_id]) @posts = @blog.posts.page(params[:page_number]).per(10) if params[:published].present? && params[:published] == "true" @posts = @posts.published.order(created_at: :desc) - else + elsif params[:draft].present? && params[:draft] == "true" @posts = @posts.draft.order(updated_at: :desc) + else + @posts = @posts.order(published_at: :desc) end end def set_post @post = Storytime::Post.friendly.find(params[:id])