Class: Releaf::Responders::AfterSaveResponder

Inherits:
ActionController::Responder
  • Object
show all
Defined in:
app/lib/releaf/responders/after_save_responder.rb

Instance Method Summary collapse

Instance Method Details

#json_resource_errorsObject


5
6
7
# File 'app/lib/releaf/responders/after_save_responder.rb', line 5

def json_resource_errors
  {errors: Releaf::BuildErrorsHash.call(resource: resource, field_name_prefix: :resource)}
end

#render_notification?Boolean

Returns:

  • (Boolean)

22
23
24
# File 'app/lib/releaf/responders/after_save_responder.rb', line 22

def render_notification?
  !(format == :json && has_errors?)
end

#respondObject


17
18
19
20
# File 'app/lib/releaf/responders/after_save_responder.rb', line 17

def respond
  render_notification(!has_errors?) if render_notification?
  super
end

#to_jsonObject


9
10
11
12
13
14
15
# File 'app/lib/releaf/responders/after_save_responder.rb', line 9

def to_json
  if has_errors?
    display_errors
  else
    redirect_to resource_location, status: 303, turbolinks: false
  end
end