Class: Locomotive::ActionController::PublicResponder

Inherits:
ActionController::Responder
  • Object
show all
Defined in:
lib/locomotive/action_controller/public_responder.rb

Instance Method Summary collapse

Instance Method Details

#api_locationObject



15
16
17
# File 'lib/locomotive/action_controller/public_responder.rb', line 15

def api_location
  success_location
end

#callback_url(state) ⇒ Object



64
65
66
# File 'lib/locomotive/action_controller/public_responder.rb', line 64

def callback_url(state)
  self.controller.params[:"#{state}_callback"]
end

#content_entryObject

get the content entry from the controller



56
57
58
# File 'lib/locomotive/action_controller/public_responder.rb', line 56

def content_entry
  self.controller.instance_variable_get :@entry
end

#error_locationObject



47
48
49
# File 'lib/locomotive/action_controller/public_responder.rb', line 47

def error_location
  callback_url(:error) || (page_path ? request.path : '/')
end


5
6
7
8
9
10
11
12
13
# File 'lib/locomotive/action_controller/public_responder.rb', line 5

def navigation_behavior(error)
  if get?
    raise error
  elsif has_errors? && default_action
    navigation_error_behavior
  else
    navigation_success_behavior
  end
end


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/locomotive/action_controller/public_responder.rb', line 19

def navigation_error_behavior
  if error_location =~ %r(^http://)
    # simple redirection for outside urls
    redirect_to error_location
  else
    path = page_path ? page_path : extract_locale_and_path(error_location)

    # render the locomotive page
    assigns = {}

    if content_entry
      slug  = content_entry.content_type.slug.singularize
      entry = content_entry.to_presenter(include_errors: true).as_json
      assigns[slug] = entry
    end

    self.controller.send :render_locomotive_page, path, assigns
  end
end


39
40
41
42
43
44
45
# File 'lib/locomotive/action_controller/public_responder.rb', line 39

def navigation_success_behavior
  # store in session the newly created content entry
  self.controller.flash['submitted_entry_id'] = self.content_entry.try(:_id).try(:to_s)

  # redirect to a locomotive page
  redirect_to success_location
end

#page_pathObject



60
61
62
# File 'lib/locomotive/action_controller/public_responder.rb', line 60

def page_path
  self.controller.params[:path]
end

#success_locationObject



51
52
53
# File 'lib/locomotive/action_controller/public_responder.rb', line 51

def success_location
  callback_url(:success) || (page_path ? request.path : '/')
end