Class: Admin::PostsController

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

Instance Method Summary collapse

Methods included from PostViewForAction

#post_view_for_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



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

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



42
43
44
45
# File 'app/controllers/admin/posts_controller.rb', line 42

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



30
31
32
33
# File 'app/controllers/admin/posts_controller.rb', line 30

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

#previewObject



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

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

#render_previewObject



57
58
59
# File 'app/controllers/admin/posts_controller.rb', line 57

def render_preview
  render template: post_view_for_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
27
28
# File 'app/controllers/admin/posts_controller.rb', line 23

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