Module: Customs::Statuses

Defined in:
lib/customs/statuses.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
# File 'lib/customs/statuses.rb', line 4

def self.included base
  base.class_attribute :navigational_formats
  base.navigational_formats = [:html]
end

Instance Method Details

#access_deniedObject



21
22
23
24
# File 'lib/customs/statuses.rb', line 21

def access_denied
  return unauthorized if self.respond_to?(:current_user) && !current_user
  forbidden
end

#options_for_status_code(code) ⇒ Object



45
46
47
# File 'lib/customs/statuses.rb', line 45

def options_for_status_code code
  { :status => code, :template => template_for_status_code(code) }
end

#template_for_status_code(code) ⇒ Object



49
50
51
# File 'lib/customs/statuses.rb', line 49

def template_for_status_code code
  "customs/#{code}"
end

#unprocessable(*args) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/customs/statuses.rb', line 26

def unprocessable *args
  options = args.extract_options!

  respond_to do |format|
    format.any *navigational_formats do
      action = options.delete(:action)
      action ||= case params[:action]
        when 'update' then 'edit'
        when 'create' then 'new'
        else raise "Unknown unprocessable action"
      end

      render :status => 422, :action => action
    end

    format.all { render :status => 422 }
  end
end