Class: Sites::Sections::ContentsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Sites::Sections::ContentsController
show all
- Defined in:
- app/controllers/cas/sites/sections/contents_controller.rb
Defined Under Namespace
Classes: FileBelongsToAnotherAttachable
Instance Method Summary
collapse
Instance Method Details
#create ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'app/controllers/cas/sites/sections/contents_controller.rb', line 18
def create
@content = ::Cas::Content.new(content_params)
success = nil
begin
ActiveRecord::Base.transaction do
@content.author_id = current_user.id
@content.section_id = @section.id
@content.tag_list = content_params[:tag_list] if content_params[:tag_list]
success = @content.save!
associate_files(@content, :images)
associate_files(@content, :attachments)
end
rescue ActiveRecord::RecordInvalid
success = nil
end
if success
redirect_to site_section_contents_url(@site, @section), notice: 'Noticia salva com sucesso.'
else
load_categories
render :new
end
end
|
#destroy ⇒ Object
78
79
80
81
82
83
|
# File 'app/controllers/cas/sites/sections/contents_controller.rb', line 78
def destroy
@content = scope_content_by_role.friendly.find(params[:id])
@content.destroy
redirect_to site_section_contents_url(@site, @section)
end
|
#edit ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
|
# File 'app/controllers/cas/sites/sections/contents_controller.rb', line 43
def edit
@content = scope_content_by_role.friendly.find(params[:id])
if @content.created_at.present? && @content.date.blank?
@default_date = @content.created_at
else
@default_date = @content.date
end
load_categories
end
|
#index ⇒ Object
8
9
10
11
|
# File 'app/controllers/cas/sites/sections/contents_controller.rb', line 8
def index
@contents = scope_content_by_role(@section.contents)
@contents = @contents.order('created_at desc').page(params[:page]).per(25)
end
|
#new ⇒ Object
13
14
15
16
|
# File 'app/controllers/cas/sites/sections/contents_controller.rb', line 13
def new
@content = ::Cas::Content.new
load_categories
end
|
#update ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'app/controllers/cas/sites/sections/contents_controller.rb', line 55
def update
@content = scope_content_by_role.friendly.find(params[:id])
success = nil
begin
ActiveRecord::Base.transaction do
@content.tag_list = content_params[:tag_list]
success = @content.update!(content_params)
associate_files(@content, :images)
associate_files(@content, :attachments)
end
rescue ActiveRecord::RecordInvalid
success = nil
end
if success
redirect_to site_section_contents_url(@site, @section)
else
load_categories
render :edit
end
end
|