class EndView::Form::RecordBuilder

Public Instance Methods

form_opts(opts = {}) click to toggle source
Calls superclass method EndView::Form::Builder#form_opts
# File lib/end_view/form/record_builder.rb, line 18
def form_opts(opts = {})
  super.merge(class: form_class, id: form_id).merge(opts)
end
input_opts(attribute, opts = {}) click to toggle source
Calls superclass method EndView::Form::Builder#input_opts
# File lib/end_view/form/record_builder.rb, line 22
def input_opts(attribute, opts = {})
  super.merge(value: attribute_value(attribute)).merge(opts)
end

Private Instance Methods

action() click to toggle source
# File lib/end_view/form/record_builder.rb, line 36
def action
  @action ||= model_id ? 'edit' : 'new'
end
attribute_id(attribute) click to toggle source
# File lib/end_view/form/record_builder.rb, line 56
def attribute_id(attribute)
  "#{model_name}_#{attribute}"
end
attribute_name(attribute) click to toggle source
# File lib/end_view/form/record_builder.rb, line 60
def attribute_name(attribute)
  "#{model_name}[#{attribute}]"
end
attribute_value(attribute) click to toggle source
# File lib/end_view/form/record_builder.rb, line 64
def attribute_value(attribute)
  (record.respond_to?(attribute) && record.send(attribute)) || nil
end
form_class() click to toggle source
# File lib/end_view/form/record_builder.rb, line 48
def form_class
  @form_class ||= "#{action}_#{model_name}"
end
form_id() click to toggle source
# File lib/end_view/form/record_builder.rb, line 52
def form_id
  @form_id ||= [action, model_name, model_id].compact.join('_')
end
form_method() click to toggle source
# File lib/end_view/form/record_builder.rb, line 40
def form_method
  @form_method ||= model_id ? 'patch' : 'post'
end
form_url() click to toggle source
# File lib/end_view/form/record_builder.rb, line 44
def form_url
  @form_url ||= "/#{Inflecto.pluralize(model_name)}/#{model_id}"
end
model_id() click to toggle source
# File lib/end_view/form/record_builder.rb, line 32
def model_id
  @model_id ||= ((record.respond_to?(:to_key) && record.to_key) || []).first
end
model_name() click to toggle source
# File lib/end_view/form/record_builder.rb, line 28
def model_name
  @model_name ||= Inflecto.underscore(Inflecto.demodulize(record.class.to_s))
end