class Formic::Form

Attributes

action[R]
model[R]

Public Instance Methods

_initialize(options={}) click to toggle source
Calls superclass method Formic::Base#_initialize
# File lib/formic/form.rb, line 7
def _initialize options={}, &block
  super options, &block
  self.options[:method] ||= 'POST'
end
_initialize_with_model(model, action, classname, options={}) click to toggle source
# File lib/formic/form.rb, line 58
def _initialize_with_model model, action, classname, options={}, &block
  options[:title] ||= "#{action} #{model.class.to_s.underscore}".gsub('_', ' ').titleize
  @model = model
  self.merge_options(options)
  self.options[:method] ||= 'POST'
  self.options[:action] ||= action
  self.options[:class].push classname
  self.content = block if block_given?
  return self
end
create(model, options={}) click to toggle source
# File lib/formic/form.rb, line 19
def create model, options={}, &block
  options[:title] ||= "New #{model.class.to_s.underscore}".gsub('_', ' ').titleize
  @action = :create

  return _initialize_with_model(
    model,
    options[:action] || self.page.url_for(model),
    "create_#{model.class.to_s.downcase}_form",
    options,
    &block
  )
end
edit(model, options={}) click to toggle source
# File lib/formic/form.rb, line 32
def edit model, options={}, &block
  self.put

  @action = :edit
  options[:title] ||= "Edit #{model.class.to_s.underscore}".gsub('_', ' ').titleize
  return _initialize_with_model(
    model,
    options[:action] || self.page.url_for(model),
    "edit_#{model.class.to_s.downcase}_form",
    options,
    &block
  )
end
method_missing(action, model, options={}) click to toggle source
# File lib/formic/form.rb, line 46
def method_missing action, model, options={}, &block
  @action = action
  options[:title] ||= "#{action} #{model.class.to_s.underscore}".gsub('_', ' ').titleize
  return _initialize_with_model(
    model,
    options[:action] || "#{self.page.url_for(model)}/#{action}",
    "#{action}_#{model.class.to_s.downcase}_form",
    options,
    &block
  )
end
put(options={}) click to toggle source
# File lib/formic/form.rb, line 12
def put options={}, &block
  self.options[:method ] = 'POST'
  self.options[:_method] = 'PUT'
  self.content = block if block_given?
  return self
end