Class: Admin::PostsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/admin/posts_controller.rb', line 21

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

  @page_title = 'New Post'

  EffectivePosts.authorized?(self, :create, @post)

  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))
    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



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/admin/posts_controller.rb', line 68

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

  EffectivePosts.authorized?(self, :destroy, @post)

  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



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

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

  EffectivePosts.authorized?(self, :edit, @post)
end

#indexObject



7
8
9
10
11
12
# File 'app/controllers/admin/posts_controller.rb', line 7

def index
  @page_title = 'Posts'
  EffectivePosts.authorized?(self, :index, Effective::Post)

  @datatable = Effective::Datatables::Posts.new() if defined?(EffectiveDatatables)
end

#newObject



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

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

  EffectivePosts.authorized?(self, :new, @post)
end

#updateObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/admin/posts_controller.rb', line 49

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

  EffectivePosts.authorized?(self, :update, @post)

  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))
    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