Module: AngularSprinkles::Helpers::FormForHelper
- Included in:
- AngularSprinkles::Helpers
- Defined in:
- lib/angular_sprinkles/helpers/form_for_helper.rb
Instance Method Summary collapse
Instance Method Details
#ng_form_for(record, submit_callback, options = {}, &block) ⇒ Object
ng_form_for
Wraps the form_for helper so that form submission can be bound an Angular service function. Accepts an additional argument which is the name of a service. Two arguments are passed to the service: the object and the Angular representation of the form.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/angular_sprinkles/helpers/form_for_helper.rb', line 12 def ng_form_for(record, submit_callback, = {}, &block) form_name = ObjectKeyWrapper.new('form', JavaScript::NoOp) record = [record] if !record.is_a?(Array) # ensures that record will be handled in the same way whether or not it's an array = { 'name' => form_name, 'ng-submit' => ng_service(submit_callback, *record.map(&:bind), form_name) }.merge([:html] || {}) = .merge(url: "", method: "", html: ) form_for(record.first, , &block).gsub('action="" ', '').html_safe end |