Module: Distribuo::Respond

Included in:
ApplicationAdminController
Defined in:
app/controllers/concerns/distribuo/respond.rb

Instance Method Summary collapse

Instance Method Details

#respond(result, options = {}) ⇒ Object

Informs the user and redirects when needed

There is also a list of options that could be used along with validators:

  • :path - Specifies where to redirect to in case of success

  • :notice - What to show on success

  • :error - What to show on error

  • :action - What action to render

  • :error_action - What action to render in case of failure

  • :model - What model to use for auto-generated notice/error flashes

Parameters:

  • result (Boolean)

    was update or create succesful

  • options (Hash) (defaults to: {})

    additional options



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/concerns/distribuo/respond.rb', line 19

def respond(result, options = {})
  options[:action]          ||= :index
  options[:error_action]    ||= :edit
  options[:continue_action] ||= options[:error_action]

  respond_flash(result, options)

  if respond_redirect?(result)
    respond_redirect(result, options)
  else
    render result ? options[:continue_action] : options[:error_action]
  end
end