Class: Admin::PostsController

Inherits:
ApplicationController
  • Object
show all
Includes:
BlogUrlHelpers, RenderPostAction
Defined in:
app/controllers/admin/posts_controller.rb

Instance Method Summary collapse

Methods included from RenderPostAction

#render_post_action

Methods included from BlogUrlHelpers

#admin_post_path, #admin_post_preview_path, #admin_posts_path, #edit_admin_post_path, #new_admin_post_path, #post_archive_path, #post_category_archive_path, #post_category_path, #post_path, #posts_path

Instance Method Details

#createObject



33
34
35
36
37
38
# File 'app/controllers/admin/posts_controller.rb', line 33

def create
  @post = SpudPost.new(post_params)
  @post.blog_key = params[:blog_key]
  flash[:notice] = 'Post was successfully created.' if @post.save
  respond_with @post, location: admin_posts_path
end

#destroyObject



40
41
42
43
# File 'app/controllers/admin/posts_controller.rb', line 40

def destroy
  flash[:notice] = 'Post was successfully deleted.' if @post.destroy
  respond_with @post, location: admin_posts_path
end

#editObject



16
17
18
# File 'app/controllers/admin/posts_controller.rb', line 16

def edit
  respond_with @post
end

#indexObject



10
11
12
13
14
# File 'app/controllers/admin/posts_controller.rb', line 10

def index
  @posts = SpudPost.for_blog(params[:blog_key]).ordered.paginate(page: params[:page], per_page: 15)
  @posts = @posts.search(params[:search]) if params[:search]
  respond_with @posts
end

#newObject



28
29
30
31
# File 'app/controllers/admin/posts_controller.rb', line 28

def new
  @post = SpudPost.new(published_at: Time.zone.now, spud_user_id: current_user.id)
  respond_with @post
end

#previewObject



45
46
47
48
49
50
51
52
53
# File 'app/controllers/admin/posts_controller.rb', line 45

def preview
  @post = if params[:post_id]
            SpudPost.find_by!(id: params[:post_id])
          else
            SpudPost.new
          end
  @post.assign_attributes(post_params)
  render_post_action :show, controller: :posts, layout: @config.layout
end

#showObject



20
21
# File 'app/controllers/admin/posts_controller.rb', line 20

def show
end

#updateObject



23
24
25
26
# File 'app/controllers/admin/posts_controller.rb', line 23

def update
  flash[:notice] = 'Post was successfully updated.' if @post.update(post_params)
  respond_with @post, location: admin_posts_path
end