Sha256: 33cafee2492aad89f59d5afef69de6b45bfde3e5b936e7c43c79afb7ca45e249
Contents?: true
Size: 1.86 KB
Versions: 1
Compression:
Stored size: 1.86 KB
Contents
class Admin::NewsPostsController < Admin::ApplicationController respond_to :html, :xml, :json before_filter :find_post, :only => [:show, :edit, :update, :destroy] add_breadcrumb 'News Posts', :admin_news_posts_path belongs_to_spud_app :news_posts def index @posts = SpudPost.where(:is_news => true).order('published_at desc').includes(:comments).paginate(:page => params[:page], :per_page => 15) respond_with @posts end def edit @categories = SpudPostCategory.grouped respond_with @post end def update @categories = SpudPostCategory.grouped params[:spud_post][:spud_site_ids] ||= [] if @post.update_attributes(post_params) flash[:notice] = 'News Post was successfully updated.' end respond_with @post, :location => admin_news_posts_path end def new @categories = SpudPostCategory.grouped @post = SpudPost.new(:published_at => Time.zone.now, :spud_user_id => current_user.id, :is_news => true, :comments_enabled => false, :spud_site_ids => [current_site_id]) respond_with @post end def create @categories = SpudPostCategory.grouped params[:spud_post][:spud_site_ids] ||= [] @post = SpudPost.new(post_params) if @post.save flash[:notice] = 'News Post was successfully created.' end respond_with @post, :location => admin_news_posts_path end def destroy if @post.destroy flash[:notice] = 'News Post was successfully deleted.' end respond_with @post, :location => admin_news_posts_path end private def find_post @post = SpudPost.find(params[:id]) if @post.blank? flash[:error] = 'News Post not found!' redirect_to admin_news_posts_path and return false end end def post_params params.require(:spud_post).permit(:published_at, :title, :content, :spud_user_id, :url_name, :visible, :comments_enabled, :meta_keywords, :meta_description, :content_format, :category_ids => [], :spud_site_ids => []) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tb_blog-1.1.0 | app/controllers/admin/news_posts_controller.rb |