errs_controller.rb
1.64 KB
1
2
3
4
5
6
7
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
49
50
51
52
53
54
55
class ErrsController < ApplicationController
before_filter :find_app, :except => [:index, :all]
def index
app_scope = current_user.admin? ? App.all : current_user.apps
respond_to do |format|
format.html do
@errs = Err.for_apps(app_scope).unresolved.ordered.paginate(:page => params[:page], :per_page => current_user.per_page)
end
format.atom do
@errs = Err.for_apps(app_scope).unresolved.ordered
end
end
end
def all
app_scope = current_user.admin? ? App.all : current_user.apps
@errs = Err.for_apps(app_scope).ordered.paginate(:page => params[:page], :per_page => current_user.per_page)
end
def show
@err = @app.errs.find(params[:id])
page = (params[:notice] || @err.notices.count)
page = 1 if page.to_i.zero?
@notices = @err.notices.ordered.paginate(:page => page, :per_page => 1)
@notice = @notices.first
end
def resolve
@err = @app.errs.find(params[:id])
# Deal with bug in mogoid where find is returning an Enumberable obj
@err = @err.first if @err.respond_to?(:first)
@err.resolve!
flash[:success] = 'Great news everyone! The err has been resolved.'
redirect_to :back
rescue ActionController::RedirectBackError
redirect_to app_path(@app)
end
protected
def find_app
@app = App.find(params[:app_id])
# Mongoid Bug: could not chain: current_user.apps.find_by_id!
# apparently finding by 'watchers.email' and 'id' is broken
raise(Mongoid::Errors::DocumentNotFound.new(App,@app.id)) unless current_user.admin? || current_user.watching?(@app)
end
end