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



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

def navigation_behavior(error)
  if get?
    raise error
  elsif has_errors? && default_action
    # get the content entry from the controller
    entry = self.controller.instance_variable_get :@entry

    if navigation_location =~ %r(^http://)
      # simple redirection for outside urls
      redirect_to navigation_location
    else
      # render the locomotive page
      self.controller.send :render_locomotive_page, navigation_location_for_locomotive, {
        entry.content_type.slug.singularize => entry.to_presenter(include_errors: true).as_json
      }
    end
  else
    entry = self.controller.instance_variable_get :@entry

    self.controller.flash['submitted_entry_id'] = entry.try(:_id).try(:to_s)

    # redirect to a locomotive page
    redirect_to navigation_location
  end
end


31
32
33
34
35
36
37
38
39
40
# File 'lib/locomotive/action_controller/public_responder.rb', line 31

def navigation_location_for_locomotive
  locale, location = self.extract_locale_and_location

  if locale
    ::I18n.locale = ::Mongoid::Fields::I18n.locale = locale
    location
  else
    navigation_location
  end
end