Class: AdminAssistant::Request::Update

Inherits:
Base
  • Object
show all
Defined in:
lib/admin_assistant/request/update.rb

Defined Under Namespace

Classes: Saving

Instance Method Summary collapse

Methods inherited from Base

#action, #after_template_file, #before_template_file, #initialize, #model_class, #model_class_symbol, #origin, #render_multi_form, #render_single_form, #render_template_file, #render_to_string, #render_to_string_if_exists

Constructor Details

This class inherits a constructor from AdminAssistant::Request::Base

Instance Method Details

#callObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/admin_assistant/request/update.rb', line 4

def call
  saving = Update::Saving.new(
    model_class.find(@controller.params[:id]), @controller
  )
  if saving.record_and_associations_valid?
    saving.save
    if @controller.params[:from]
      render_response_to_ajax_toggle saving.record
    else
      saving.redirect_after_save
    end
  else
    render_single_form saving.record
  end
end

#render_response_to_ajax_toggle(record) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/admin_assistant/request/update.rb', line 20

def render_response_to_ajax_toggle(record)
  @controller.params[:from] =~ /#{model_class.name.underscore}_\d+_(.*)/
  field_name = $1
  index = AdminAssistant::Index.new @admin_assistant
  erb = <<-ERB
    <%= index.view(self).columns.detect { |c| c.name == field_name }.
              ajax_toggle_inner_html(record) %>
  ERB
  @controller.send(
    :render,
    :inline => erb,
    :locals => {
      :index => index, :field_name => field_name, :record => record
    }
  )
end