refinerycms-blog/app/controllers/refinery/admin/blog/posts_controller.rb
Jamie Winsor 6212e60f9e index action of blog post controller now caches and sweeps on changes
fix various views which were broken and untested with rails-3-1 upgrade
add request spec tests for admin blog comments
Factory is now FactoryGirl
Fix multiple issues around listing unmoderated comments
use cleaner definitions to set per_page willpaginate attribute on models
update all paginate calls to use new arel representation
reorganize filter sections to be located at top of controller
modify uncategorized class method to activerecord scope and perform a left outer join instead of iterate through an array to find uncategorized posts
move request specs into their proper places
update guardfile to ensure that request specs get run when their respective controllers are modified
Fix show action for AdminBlogComments and added test
Fix redirection link after approving or rejecting a comment
2011-09-03 21:55:30 -07:00

97 lines
3.1 KiB
Ruby

module Refinery
module Admin
module Blog
class PostsController < ::Admin::BaseController
cache_sweeper Refinery::BlogSweeper
crudify :'refinery/blog_post',
:title_attribute => :title,
:order => 'published_at DESC'
before_filter :find_all_categories,
:only => [:new, :edit, :create, :update]
before_filter :check_category_ids, :only => :update
def uncategorized
@blog_posts = Refinery::BlogPost.uncategorized.page(params[:page])
end
def tags
op = case ActiveRecord::Base.connection.adapter_name.downcase
when 'postgresql'
'~*'
else
'LIKE'
end
wildcard = case ActiveRecord::Base.connection.adapter_name.downcase
when 'postgresql'
'.*'
else
'%'
end
@tags = Refinery::BlogPost.tag_counts_on(:tags).where(
["tags.name #{op} ?", "#{wildcard}#{params[:term].to_s.downcase}#{wildcard}"]
).map { |tag| {:id => tag.id, :value => tag.name}}
render :json => @tags.flatten
end
def create
# if the position field exists, set this object as last object, given the conditions of this class.
if Refinery::BlogPost.column_names.include?("position")
params[:blog_post].merge!({
:position => ((Refinery::BlogPost.maximum(:position, :conditions => "")||-1) + 1)
})
end
if Refinery::BlogPost.column_names.include?("user_id")
params[:blog_post].merge!({
:user_id => current_user.id
})
end
if (@blog_post = Refinery::BlogPost.create(params[:blog_post])).valid?
(request.xhr? ? flash.now : flash).notice = t(
'refinery.crudify.created',
:what => "'#{@blog_post.title}'"
)
unless from_dialog?
unless params[:continue_editing] =~ /true|on|1/
redirect_back_or_default(main_app.refinery_admin_blog_posts_path)
else
unless request.xhr?
redirect_to :back
else
render :partial => "/shared/message"
end
end
else
render :text => "<script>parent.window.location = '#{admin_blog_posts_url}';</script>"
end
else
unless request.xhr?
render :action => 'new'
else
render :partial => "/refinery/admin/error_messages",
:locals => {
:object => @blog_post,
:include_object_name => true
}
end
end
end
protected
def find_all_categories
@blog_categories = Refinery::BlogCategory.find(:all)
end
def check_category_ids
params[:blog_post][:category_ids] ||= []
end
end
end
end
end