module RPH::FormAssistant::ViewHelpers

methods that mix into ActionView::Base

Public Instance Methods

fieldset(legend, &block) click to toggle source

(borrowed the fieldset() helper from Chris Scharf:

http://github.com/scharfie/slate/tree/master/app/helpers/application_helper.rb)

<% fieldset 'User Registration' do %>

// fields

<% end %>

# File lib/form_assistant/view_helpers.rb, line 35
def fieldset(legend, &block)
  locals = { :legend => legend, :fields => capture(&block) }
  partial = render(:partial => "#{RPH::FormAssistant::FormBuilder.template_root}/fieldset.html.erb", :locals => locals)

  # render the fields
  binding_required ? concat(partial, block.binding) : concat(partial)
end
form_assistant_for(record_or_name_or_array, *args, &proc) click to toggle source

easy way to make use of FormAssistant::FormBuilder

<% form_assistant_for @project do |form| %>

// fancy form stuff

<% end %>

# File lib/form_assistant/view_helpers.rb, line 25
def form_assistant_for(record_or_name_or_array, *args, &proc)
  form_for_with_builder(record_or_name_or_array, RPH::FormAssistant::FormBuilder, *args, &proc)
end

Private Instance Methods

binding_required() click to toggle source

determines if binding is needed for concat() (Rails 2.2.0 and greater no longer requires the binding)

# File lib/form_assistant/view_helpers.rb, line 15
def binding_required
  RPH::FormAssistant::Rules.binding_required?
end
form_for_with_builder(record_or_name_or_array, builder, *args, &proc) click to toggle source

used to ensure that the desired builder gets set before calling form_for()

# File lib/form_assistant/view_helpers.rb, line 7
def form_for_with_builder(record_or_name_or_array, builder, *args, &proc)
  options = args.extract_options!
  # hand control over to the original #form_for()
  form_for(record_or_name_or_array, *(args << options.merge!(:builder => builder)), &proc)
end