Class: IshManager::ReportsController
Instance Method Summary
collapse
#basic_auth, #home, #tinymce
Instance Method Details
#create ⇒ Object
8
9
10
11
12
13
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
|
# File 'app/controllers/ish_manager/reports_controller.rb', line 8
def create
@report = Report.new params[:report].permit!
@report.user_profile = @current_profile authorize! :create, @report
flag = @report.save
respond_to do |format|
if flag
if params[:report][:photo]
photo = Photo.new
photo.photo = params[:report][:photo]
photo.is_public = @report.is_public
photo.is_trash = false
photo.report_id = @report.id
photo.save
end
format.html do
redirect_to report_path(@report), :notice => 'Report was successfully created.'
end
format.json { render :json => @report, :status => :created, :location => @report } else
format.html do
flash[:alert] = @report.errors.full_messages
@tags_list = []
render :action => "new"
end
format.json { render :json => @report.errors, :status => :unprocessable_entity } end
end
end
|
#destroy ⇒ Object
43
44
45
46
47
48
49
|
# File 'app/controllers/ish_manager/reports_controller.rb', line 43
def destroy
@report = Report.unscoped.find params[:id]
authorize! :destroy, @report
@report.is_trash = true
@report.save
redirect_to request.referrer
end
|
#edit ⇒ Object
51
52
53
54
|
# File 'app/controllers/ish_manager/reports_controller.rb', line 51
def edit
@report = Report.unscoped.find params[:id]
authorize! :edit, @report
end
|
#index ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'app/controllers/ish_manager/reports_controller.rb', line 56
def index
authorize! :index, Report
@reports = Report.unscoped.order_by( :created_at => :desc
).where( :is_trash => false, :user_profile => @current_profile
).page( params[:reports_page] ).per( Report::PER_PAGE )
if params[:q]
@reports = @reports.or({ slug: /#{params[:q]}/i }, { name: /#{params[:q]}}/i }) if @reports.length == 1
redirect_to report_path(@reports[0])
return
end
end
end
|
#new ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'app/controllers/ish_manager/reports_controller.rb', line 70
def new
@report = Report.new
authorize! :new, @report
@tags_list = []
respond_to do |format|
format.html do
render
end
format.json { render :json => @report }
end
end
|
#show ⇒ Object
83
84
85
86
|
# File 'app/controllers/ish_manager/reports_controller.rb', line 83
def show
@report = Report.unscoped.find params[:id]
authorize! :show, @report
end
|
#update ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'app/controllers/ish_manager/reports_controller.rb', line 88
def update
@report = Report.unscoped.find params[:id]
authorize! :update, @report
if params[:photo]
photo = Photo.new :photo => params[:photo]
@report.update_attributes( :photo => photo, :updated_at => Time.now )
end
respond_to do |format|
if @report.update_attributes(params[:report].permit!)
format.html do
redirect_to report_path(@report), :notice => 'Report was successfully updated.'
end
format.json { head :ok }
else
format.html { render :action => "edit" }
format.json { render :json => @report.errors, :status => :unprocessable_entity }
end
end
end
|