From a3349f845ffa2415e12ac9e26b4f7300d7edd3ef Mon Sep 17 00:00:00 2001 From: "Stephen St. Martin" Date: Sun, 31 Jan 2010 14:42:40 -0500 Subject: form_for should pass :remote to form_tag through html_options --- actionpack/lib/action_view/helpers/form_helper.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack/lib/action_view/helpers/form_helper.rb') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 20e9916d62..54610fdc71 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -280,6 +280,8 @@ module ActionView args.unshift object end + options[:html][:remote] = true if options.delete(:remote) + concat(form_tag(options.delete(:url) || {}, options.delete(:html) || {})) fields_for(object_name, *(args << options), &proc) concat(''.html_safe!) -- cgit v1.2.3 From c493370f332715dee0ef795a66e896d7f0471cbe Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Sun, 31 Jan 2010 16:30:21 -0600 Subject: UJS documentation. --- actionpack/lib/action_view/helpers/form_helper.rb | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'actionpack/lib/action_view/helpers/form_helper.rb') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 54610fdc71..a72357cf3d 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -225,6 +225,33 @@ module ActionView # ... # <% end %> # + # === Unobtrusive JavaScript + # + # Specifying: + # + # :remote => true + # + # in the options hash creates a form that will allow the unobtrusive JavaScript drivers to modify its + # behaviour. The expected default behaviour is an XMLHttpRequest in the background instead of the regular + # POST arrangement, but ultimately the behaviour is the choice of the JavaScript driver implementor. + # Even though it's using JavaScript to serialize the form elements, the form submission will work just like + # a regular submission as viewed by the receiving side (all elements available in params). + # + # Example: + # + # <% form_for(:post, @post, :remote => true, :html => { :id => 'create-post', :method => :put }) do |f| %> + # ... + # <% end %> + # + # The HTML generated for this would be: + # + #
+ #
+ # + #
+ # ... + #
+ # # === Customized form builders # # You can also build forms using a customized FormBuilder class. Subclass -- cgit v1.2.3 From 4cbb9db0a5ff65b0a626a5b043331abefd89e717 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sun, 31 Jan 2010 19:17:42 -0800 Subject: For performance reasons, you can no longer call html_safe! on Strings. Instead, all Strings are always not html_safe?. Instead, you can get a SafeBuffer from a String by calling #html_safe, which will SafeBuffer.new(self). * Additionally, instead of doing concat("".html_safe), you can do safe_concat(""), which will skip both the flag set, and the flag check. * For the first pass, I converted virtually all #html_safe!s to #html_safe, and the tests pass. A further optimization would be to try to use #safe_concat as much as possible, reducing the performance impact if we know up front that a String is safe. --- actionpack/lib/action_view/helpers/form_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_view/helpers/form_helper.rb') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index a72357cf3d..76998a6ea1 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -311,7 +311,7 @@ module ActionView concat(form_tag(options.delete(:url) || {}, options.delete(:html) || {})) fields_for(object_name, *(args << options), &proc) - concat(''.html_safe!) + safe_concat('') end def apply_form_for_options!(object_or_array, options) #:nodoc: @@ -879,7 +879,7 @@ module ActionView end hidden = tag("input", "name" => options["name"], "type" => "hidden", "value" => options['disabled'] && checked ? checked_value : unchecked_value) checkbox = tag("input", options) - (hidden + checkbox).html_safe! + (hidden + checkbox).html_safe end def to_boolean_select_tag(options = {}) -- cgit v1.2.3