Class: Locomotive::ActionController::Responder

Inherits:
ActionController::Responder
  • Object
show all
Includes:
Responders::FlashResponder
Defined in:
lib/locomotive/action_controller/responder.rb

Instance Method Summary collapse

Instance Method Details

#optionsObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/locomotive/action_controller/responder.rb', line 12

def options
  current_site    = self.controller.send(:current_site)
   = self.controller.send(:current_locomotive_account)
  ability         = current_site.nil? || .nil? ? nil : self.controller.send(:current_ability)

  super.merge({
    current_site:     current_site,
    current_account:  ,
    ability:          ability
  })
end

#set_flash_now?Boolean

by default flash_now messages if the resource has errors

Returns:



8
9
10
# File 'lib/locomotive/action_controller/responder.rb', line 8

def set_flash_now?
  super || has_errors?
end

#to_jsonObject



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
# File 'lib/locomotive/action_controller/responder.rb', line 24

def to_json
  if get?
    add_pagination_header if resource.respond_to?(:num_pages)
    display resource
  elsif has_errors?
    with_flash_message(:alert) do
      display resource.errors, status: :unprocessable_entity
    end
  elsif post?
    in_header = controller.request.headers['X-Flash'] == 'true'
    with_flash_message(:notice, in_header) do
      display resource, location: api_location
    end
  elsif put?
    with_flash_message do |message|
      display resource, status: :ok, location: api_location
    end
  elsif delete?
    with_flash_message do |message|
      display resource, status: :ok, location: api_location
    end
  elsif has_empty_resource_definition?
    display empty_resource, status: :ok
  else
    with_flash_message do
      head :ok
    end
  end
end