aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/form_helper.rb
diff options
context:
space:
mode:
authorMikel Lindsaar <raasdnil@gmail.com>2010-02-02 13:30:08 +1100
committerMikel Lindsaar <raasdnil@gmail.com>2010-02-02 13:30:08 +1100
commit535ae3b946b387af7eb6cb4bb4aed3d5cac1cf81 (patch)
treedcbd2acf8e83493eea719bf0a0c51a9c121bf194 /actionpack/lib/action_view/helpers/form_helper.rb
parent49a26c533366eff63acd3c99ed0dffc04f85f55c (diff)
parent9b5dae7af5757769c1e69d74a59ff036adc1f30f (diff)
downloadrails-535ae3b946b387af7eb6cb4bb4aed3d5cac1cf81.tar.gz
rails-535ae3b946b387af7eb6cb4bb4aed3d5cac1cf81.tar.bz2
rails-535ae3b946b387af7eb6cb4bb4aed3d5cac1cf81.zip
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'actionpack/lib/action_view/helpers/form_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb33
1 files changed, 31 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 157deebe40..1d91b6957a 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 <tt>params</tt>).
+ #
+ # Example:
+ #
+ # <% form_for(:post, @post, :remote => true, :html => { :id => 'create-post', :method => :put }) do |f| %>
+ # ...
+ # <% end %>
+ #
+ # The HTML generated for this would be:
+ #
+ # <form action='http://www.example.com' id='create-post' method='post' data-remote='true'>
+ # <div style='margin:0;padding:0;display:inline'>
+ # <input name='_method' type='hidden' value='put' />
+ # </div>
+ # ...
+ # </form>
+ #
# === Customized form builders
#
# You can also build forms using a customized FormBuilder class. Subclass
@@ -280,9 +307,11 @@ 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('</form>'.html_safe!)
+ safe_concat('</form>')
end
def apply_form_for_options!(object_or_array, options) #:nodoc:
@@ -850,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 = {})