Class: Storytime::Dashboard::CustomPostsController

Inherits:
BlogPostsController show all
Defined in:
app/controllers/storytime/dashboard/custom_posts_controller.rb

Instance Method Summary collapse

Methods inherited from BlogPostsController

#destroy

Methods inherited from PostsController

#destroy, #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



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

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

#newObject



5
6
7
8
9
10
# File 'app/controllers/storytime/dashboard/custom_posts_controller.rb', line 5

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