Class: DmCms::Admin::CmsPostsController

Inherits:
AdminController
  • Object
show all
Includes:
PermittedParams
Defined in:
app/controllers/dm_cms/admin/cms_posts_controller.rb

Instance Method Summary collapse

Methods included from PermittedParams

#cms_blog_params, #cms_contentitem_params, #cms_page_params, #cms_post_params, #cms_snippet_params, #media_file_params

Instance Method Details

#createObject




19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/dm_cms/admin/cms_posts_controller.rb', line 19

def create
  authorize! :manage_content, @blog
  @post = @blog.posts.new(cms_post_params)

  if @post.save
    redirect_to admin_cms_blog_url(@blog), notice: 'Post was successfully created.'
  else
    render action: :new
  end
end

#destroyObject




41
42
43
44
45
# File 'app/controllers/dm_cms/admin/cms_posts_controller.rb', line 41

def destroy
  authorize! :manage_content, @blog
  @post.destroy
  redirect_to admin_cms_blog_url(@blog), notice: 'Post was successfully deleted.'
end

#editObject




14
15
16
# File 'app/controllers/dm_cms/admin/cms_posts_controller.rb', line 14

def edit
  authorize! :manage_content, @blog
end

#newObject




8
9
10
11
# File 'app/controllers/dm_cms/admin/cms_posts_controller.rb', line 8

def new
  authorize! :manage_content, @blog
  @post = @blog.posts.build(comments_allowed: @blog.comments_allowed)
end

#send_notifications_emailsObject




48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/dm_cms/admin/cms_posts_controller.rb', line 48

def send_notifications_emails
  authorize! :manage_content, @blog
  status = @post.send_notification_emails(params[:test] ? current_user : nil)
  if params[:test] && status == 0
    redirect_to admin_cms_blog_url(@blog), error: "Unable to send test email"
  else
    msg = params[:test] ? "Test notification sent to #{current_user.email}" : "#{status} emails are being sent"
    redirect_to admin_cms_blog_url(@blog), notice: msg
  end
end

#updateObject




31
32
33
34
35
36
37
38
# File 'app/controllers/dm_cms/admin/cms_posts_controller.rb', line 31

def update
  authorize! :manage_content, @blog
  if @post.update_attributes(cms_post_params)
    redirect_to admin_cms_blog_url(@blog), notice: 'Post was successfully updated.'
  else
    render action: :edit
  end
end