Class: Storytime::Dashboard::PostsController
Instance Method Summary
collapse
#authenticate_user!, #current_user, #setup, #user_signed_in?
#current_storytime_site
#content_for, #content_for?, #view_context
Instance Method Details
#create ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'app/controllers/storytime/dashboard/posts_controller.rb', line 38
def create
@post = new_post(post_params)
@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
|
#destroy ⇒ Object
73
74
75
76
77
78
79
80
81
|
# File 'app/controllers/storytime/dashboard/posts_controller.rb', line 73
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, current_post_type], type: @post.type_name }
end
end
|
#edit ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
|
# File 'app/controllers/storytime/dashboard/posts_controller.rb', line 26
def edit
authorize @post
if params[:autosave]
if @post.autosave
@post.draft_content = @post.autosave.content
else
redirect_to [:edit, :dashboard, @post]
end
end
end
|
#index ⇒ Object
17
18
19
|
# File 'app/controllers/storytime/dashboard/posts_controller.rb', line 17
def index
authorize @posts
end
|
#new ⇒ Object
21
22
23
24
|
# File 'app/controllers/storytime/dashboard/posts_controller.rb', line 21
def new
@post = new_post
authorize @post
end
|
#update ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'app/controllers/storytime/dashboard/posts_controller.rb', line 57
def update
authorize @post
@post.draft_user_id = current_user.id
if @post.update(post_params)
@post.autosave.destroy unless @post.autosave.nil?
send_subscriber_notifications if @post.published? && post_params[:notifications_enabled] == "1"
redirect_to [:edit, :dashboard, @post], notice: I18n.t('flash.posts.update.success')
else
load_media
render :edit
end
end
|