Module: FormForWithResourceHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/form_for_with_resource_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.form_for_with_resource_option(form_helper, record, options) ⇒ Object

Handles the +:resource+ option in +form_for+.


5
6
7
8
9
10
11
12
13
14
15
# File 'app/helpers/form_for_with_resource_helper.rb', line 5

def form_for_with_resource_option(form_helper, record, options)
  case options[:resource]
  when Symbol
    raise ArgumentError, ':resource and :url cannot both be specified' if options[:url]
    helper = url_helper_for_resource(record, options.delete(:resource))
    options[:url] = form_helper.send(helper, *record)
  when nil
  else
    raise ArgumentError, 'Resource must be a symbol with the stem of route helper'
  end
end

Instance Method Details

#form_for(record, options, &proc) ⇒ Object


63
64
65
66
67
# File 'app/helpers/form_for_with_resource_helper.rb', line 63

def form_for(record, options, &proc)
  FormForWithResourceHelper.form_for_with_resource_option(self, record, options)

  super(record, options, &proc)
end