Module: Tramway::Admin::FrontendHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/tramway/admin/frontend_helper.rb

Instance Method Summary collapse

Instance Method Details

#react_params(form, action, method) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/tramway/admin/frontend_helper.rb', line 2

def react_params(form, action, method)
  url = case action
        when :create
          Tramway::Admin::Engine.routes.url_helpers.records_path(model: form.model.class)
        else
          Tramway::Admin::Engine.routes.url_helpers.record_path(form.model.id, model: form.model.class)
        end
  form.properties.reduce({ action: url, method: method, authenticity_token: form_authenticity_token }) do |hash, property|
    case property[1]
    when :association
      hash.merge!(
        property[0] => {
          collection: build_collection_for_association(form, property[0])
        }
      )
    end
    hash
  end.merge model: form.model.attributes
end