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
42
43
44
45
46
47
48
|
# File 'app/controllers/ish_manager/reports_controller.rb', line 8
def create
authorize! :create, Report
if params[:report][:shared_profiles].present?
params[:report][:shared_profiles].delete('')
end
params[:report][:shared_profile_ids] = params[:report][:shared_profiles]
params[:report].delete :shared_profiles
@report = Report.new params[:report].permit!
@report.user_profile = @current_profile
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
50
51
52
53
54
55
56
|
# File 'app/controllers/ish_manager/reports_controller.rb', line 50
def destroy
@report = Report.unscoped.find params[:id]
authorize! :destroy, @report
@report.is_trash = true
@report.save
redirect_to request.referrer
end
|
#edit ⇒ Object
58
59
60
61
|
# File 'app/controllers/ish_manager/reports_controller.rb', line 58
def edit
@report = Report.unscoped.find params[:id]
authorize! :edit, @report
end
|
#index ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'app/controllers/ish_manager/reports_controller.rb', line 63
def index
authorize! :index, Report
@reports = Report.unscoped.order_by( :created_at => :desc
).where( :is_trash => false, :user_profile => @current_profile )
if params[:q]
@reports = @reports.where({ :name => /#{params[:q]}/i })
if @reports.length == 1
redirect_to report_path(@reports[0])
return
end
end
@reports = @reports.page( params[:reports_page] ).per( Report::PER_PAGE )
end
|
#new ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'app/controllers/ish_manager/reports_controller.rb', line 78
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
91
92
93
94
|
# File 'app/controllers/ish_manager/reports_controller.rb', line 91
def show
@report = Report.unscoped.find params[:id]
authorize! :show, @report
end
|
#update ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'app/controllers/ish_manager/reports_controller.rb', line 96
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
old_shared_profile_ids = @report.shared_profiles.map(&:id)
if params[:report][:shared_profiles].present?
params[:report][:shared_profiles].delete('')
end
params[:report][:shared_profile_ids] = params[:report][:shared_profiles]
params[:report].delete :shared_profiles
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
|