Class: Storytime::Dashboard::BlogPostsController

Inherits:
PostsController show all
Defined in:
app/controllers/storytime/dashboard/blog_posts_controller.rb

Direct Known Subclasses

CustomPostsController

Instance Method Summary collapse

Methods inherited from PostsController

#edit, #index, #update

Methods inherited from ApplicationController

#authenticate_user!, #current_user, #setup, #user_signed_in?

Methods included from Concerns::CurrentSite

#current_storytime_site

Methods included from Concerns::ControllerContentFor

#content_for, #content_for?, #view_context

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/storytime/dashboard/blog_posts_controller.rb', line 14

def create
  @post = current_post_type.new(post_params)
  @post.blog = Storytime::Blog.friendly.find(params[:blog_id])
  @post.user = current_user
  @post.draft_user_id = current_user.id
  authorize @post

  if @post.save
    @post.create_autosave(post_params.slice(:draft_content)) if params[:preview] == "true"

    send_subscriber_notifications if @post.published? && post_params[:notifications_enabled] == "1"

    opts = params[:preview] == "true" ? { preview: true } : {}

    redirect_to [:edit, :dashboard, @post, opts], notice: I18n.t('flash.posts.create.success')
  else
    load_media
    render :new
  end
end

#destroyObject



35
36
37
38
39
40
41
42
43
# File 'app/controllers/storytime/dashboard/blog_posts_controller.rb', line 35

def destroy
  authorize @post
  @post.destroy
  flash[:notice] = I18n.t('flash.posts.destroy.success') unless request.xhr?

  respond_with [:dashboard, @post] do |format|
    format.html{ redirect_to [:dashboard, @post.blog, :blog_page_post_index] }
  end
end

#newObject



7
8
9
10
11
12
# File 'app/controllers/storytime/dashboard/blog_posts_controller.rb', line 7

def new
  @post = current_post_type.new
  @post.blog = Storytime::Blog.friendly.find(params[:blog_id])
  @post.user = current_user
  authorize @post
end