Class: CamaleonCms::Admin::Posts::DraftsController
Instance Method Summary
collapse
#ajax, #edit, #new, #restore, #show, #trash
#ajax, #cama_get_i18n_frontend, #dashboard, #search
Instance Method Details
#create ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'app/controllers/camaleon_cms/admin/posts/drafts_controller.rb', line 14
def create
if @draft_parent_post.present?
authorize! :update, @draft_parent_post
@post_draft = @post_type.posts.drafts.where(post_parent: @draft_parent_post.id,
user_id: cama_current_user.id).first
if @post_draft.present?
@post_draft.set_option('draft_status', @post_draft.status)
@post_draft.attributes = @post_data
end
else
authorize! :create_post, @post_type
end
if @post_draft.blank?
@post_draft = @post_type.posts.new(@post_data)
@post_draft.user_id = cama_current_user.id
end
r = { post: @post_draft, post_type: @post_type }
hooks_run('create_post_draft', r)
if @post_draft.save(validate: false)
@post_draft.set_params(params[:meta], cama_permitted_field_options('PostType_Post'), @post_data[:keywords])
msg = { draft: { id: @post_draft.id },
_drafts_path: cama_admin_post_type_draft_path(@post_type.id, @post_draft) }
r = { post: @post_draft, post_type: @post_type }
hooks_run('created_post_draft', r)
else
msg = { error: @post_draft.errors.full_messages }
end
render json: msg
end
|
#destroy ⇒ Object
72
|
# File 'app/controllers/camaleon_cms/admin/posts/drafts_controller.rb', line 72
def destroy; end
|
#index ⇒ Object
7
8
9
10
11
12
|
# File 'app/controllers/camaleon_cms/admin/posts/drafts_controller.rb', line 7
def index
authorize! :posts, @post_type
render json: @post_type
end
|
#update ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'app/controllers/camaleon_cms/admin/posts/drafts_controller.rb', line 50
def update
@post_draft = @post_type.posts.drafts.where(user_id: cama_current_user.id).find(params[:id])
authorize! :update, @post_draft.parent || @post_draft
@post_draft.attributes = @post_data
r = { post: @post_draft, post_type: @post_type }
hooks_run('update_post_draft', r)
if @post_draft.save(validate: false)
@post_draft.set_params(params[:meta], cama_permitted_field_options('PostType_Post'), params[:options])
hooks_run('updated_post_draft', { post: @post_draft, post_type: @post_type })
msg = { draft: { id: @post_draft.id } }
else
msg = { error: @post_draft.errors.full_messages }
end
render json: msg
rescue ActiveRecord::RecordNotFound
flash[:error] = t('camaleon_cms.admin.post.message.error', post_type: @post_type.decorate.the_title)
redirect_to cama_admin_path
end
|