Class: Admin::PostsController

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

Instance Method Summary collapse

Instance Method Details

#approveObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/controllers/admin/posts_controller.rb', line 93

def approve
  @post = Effective::Post.find(params[:id])
  @page_title = 'Approve Post'

  authorize_effective_posts!

  if @post.update_attributes(draft: false)
    flash[:success] = 'Successfully approved post.  It is now displayed on the website.'
  else
    flash[:danger] = "Unable to approve post: #{@post.errors.full_messages.join(', ')}"
  end

  redirect_to(:back) rescue redirect_to(effective_posts.admin_posts_path)
end

#createObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/admin/posts_controller.rb', line 26

def create
  @post = Effective::Post.new(post_params)
  @post.user = current_user if defined?(current_user)

  @page_title = 'New Post'

  authorize_effective_posts!

  if @post.save
    if params[:commit] == 'Save and Edit Content' && defined?(EffectiveRegions)
      redirect_to effective_regions.edit_path(effective_posts.post_path(@post), :exit => effective_posts.edit_admin_post_path(@post))
    elsif params[:commit] == 'Save and Add New'
      flash[:success] = 'Successfully created post'
      redirect_to effective_posts.new_admin_post_path
    else
      flash[:success] = 'Successfully created post'
      redirect_to effective_posts.edit_admin_post_path(@post)
    end
  else
    flash.now[:danger] = 'Unable to create post'
    render :action => :new
  end
end

#destroyObject



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/admin/posts_controller.rb', line 79

def destroy
  @post = Effective::Post.find(params[:id])

  authorize_effective_posts!

  if @post.destroy
    flash[:success] = 'Successfully deleted post'
  else
    flash[:danger] = 'Unable to delete post'
  end

  redirect_to effective_posts.admin_posts_path
end

#editObject



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

def edit
  @post = Effective::Post.find(params[:id])
  @page_title = 'Edit Post'

  authorize_effective_posts!
end

#excerptsObject



108
109
110
111
112
113
# File 'app/controllers/admin/posts_controller.rb', line 108

def excerpts
  @posts = Effective::Post.includes(:regions)
  @page_title = 'Post Excerpts'

  authorize_effective_posts!
end

#indexObject



7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/admin/posts_controller.rb', line 7

def index
  @page_title = 'Posts'

  if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
    @datatable = Effective::Datatables::Posts.new()
  else
    @datatable = EffectivePostsDatatable.new(self)
  end

  authorize_effective_posts!
end

#newObject



19
20
21
22
23
24
# File 'app/controllers/admin/posts_controller.rb', line 19

def new
  @post = Effective::Post.new(published_at: Time.zone.now)
  @page_title = 'New Post'

  authorize_effective_posts!
end

#updateObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/admin/posts_controller.rb', line 57

def update
  @post = Effective::Post.find(params[:id])
  @page_title = 'Edit Post'

  authorize_effective_posts!

  if @post.update_attributes(post_params)
    if params[:commit] == 'Save and Edit Content' && defined?(EffectiveRegions)
      redirect_to effective_regions.edit_path(effective_posts.post_path(@post), :exit => effective_posts.edit_admin_post_path(@post))
    elsif params[:commit] == 'Save and Add New'
      flash[:success] = 'Successfully updated post'
      redirect_to effective_posts.new_admin_post_path
    else
      flash[:success] = 'Successfully updated post'
      redirect_to effective_posts.edit_admin_post_path(@post)
    end
  else
    flash.now[:danger] = 'Unable to update post'
    render :action => :edit
  end
end