lib/mack/view_helpers/form_helpers.rb in mack-0.8.2 vs lib/mack/view_helpers/form_helpers.rb in mack-0.8.3
- old
+ new
@@ -10,11 +10,11 @@
# Only call this method if you generate the form manually.
# If you use the form() method to generate your form, then
# the authenticity token is already included in your form.
#
def form_authenticity_field
- str = %{<input type="hidden" name="__authenticity_token" value="#{Mack::Utils::AuthenticityTokenDispenser.instance.dispense_token(request.session.id)}" />}
+ str = %{<input type="hidden" name="__authenticity_token" value="#{Mack::Utils::AuthenticityTokenDispenser.instance.dispense_token(request.session.id)}" />\n}
end
# Examples:
# <% form(users_create_url) do -%>
@@ -28,10 +28,11 @@
# <% form(photos_create_url, :multipart => true) do -%>
# # form stuff here...
# <% end -%>
def form(action, options = {}, &block)
options = {:method => :post, :action => action}.merge(options)
+ form_builder = options.delete(:builder) || configatron.mack.default_form_builder.camelcase.constantize.new(Thread.current[:view_template])
if options[:id]
options = {:class => options[:id]}.merge(options)
end
if options[:multipart]
options = {:enctype => "multipart/form-data"}.merge(options)
@@ -43,11 +44,11 @@
options[:method] = :post
end
concat("<form#{build_options(options)}>\n", block.binding)
concat(meth, block.binding) unless meth.blank?
concat(form_authenticity_field, block.binding) unless configatron.mack.disable_forgery_detector
- yield
+ yield form_builder
concat("\n</form>", block.binding)
# content_tag(:form, options, &block)
end
# Generates a button with a form around it and will set the request method to delete.
@@ -258,19 +259,19 @@
content_tag(:label, fe.options, content)
end
private
def label_parameter_tag(name, id, var, fe)
- label = ""
+ label = ''
if fe.options[:label]
if fe.options[:label].is_a?(TrueClass)
if var.nil?
- label = %{<label for="#{id}">#{name.to_s.humanize}</label>}
+ label = %{<label for="#{id}">#{name.to_s.humanize}</label>\n}
else
- label = %{<label for="#{id}">#{fe.calling_method.to_s.humanize}</label>}
+ label = %{<label for="#{id}">#{fe.calling_method.to_s.humanize}</label>\n}
end
else
- label = %{<label for="#{id}">#{fe.options[:label]}</label>}
+ label = %{<label for="#{id}">#{fe.options[:label]}</label>\n}
end
fe.options.delete(:label)
end
return label
end
\ No newline at end of file