Module: Reactive::WxOutput::Binder

Includes:
Helpers::FormsHelper
Included in:
DefaultHandler, Helpers::AssetHelper::AssetArtProvider
Defined in:
lib/reactive-wx/binder.rb

Instance Method Summary collapse

Methods included from Helpers::FormsHelper

#form_name_and_container, #form_to_param, #forms_to_params

Instance Method Details

#do_request(*args) ⇒ Object

Let Reactive do the request The hash argument may be of three forms:

* Direct form: a record (for CRUD actions, the action is known by asking the record: CREATE => new_record?, UPDATE => changed?, DELETE => marked_for_destruction?, SHOW => none of them)
   You may override the action by passing an :action entry in the options. A special action named :save will auto-determine the :create or :update state.
* Simple form: a params hash with at least entries for :controller and :action
* Complex form: a hash with a :link entry

TODO: Refactor this new_params creation process



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/reactive-wx/binder.rb', line 16

def do_request(*args)
  hash = args.extract_options!
  record = args.first
  if record.class.respond_to?(:meta) && record.class.meta.is_a?(MetaModel::Model)
    options = hash
    new_params = hash.merge(:model => record)
  else
    # params may be of two forms, a simple params hash or a complex hash with embedded hashes. To distinguish: if the hash contains a :link key it is a complex one.
    params, options = hash.has_key?(:link) ? [hash[:link], hash] : [hash, {}]
    new_params = params.dup
    
    # handle forms params
    new_params.update(forms_to_params(options[:forms]))
    
    # handle late update of params
  #        return false unless handle_late_tag(options[:late], new_params, wx_event)
    
  end
  # set up the request
  request = Request.new(new_params)
  request.local_assigns = options[:locals]
  
  # let the request run
  Dispatcher::Base.dispatch(request)
end