aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2007-09-02 23:53:31 +0000
committerMichael Koziarski <michael@koziarski.com>2007-09-02 23:53:31 +0000
commit21837821a804f6c26a0672f9ce5697e198624968 (patch)
treea8b54c7902f360c9b9eabcf10e1e821baee32eb9 /actionpack/lib
parentb18d9568a64b9b3605db90f93e6fcbf77344d010 (diff)
downloadrails-21837821a804f6c26a0672f9ce5697e198624968.tar.gz
rails-21837821a804f6c26a0672f9ce5697e198624968.tar.bz2
rails-21837821a804f6c26a0672f9ce5697e198624968.zip
Add array support to remote_form_for for polymorphic urls. Closes #8654 [jade]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7400 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_view/helpers/prototype_helper.rb50
1 files changed, 44 insertions, 6 deletions
diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb
index 0da5cc5579..4ece6f8709 100644
--- a/actionpack/lib/action_view/helpers/prototype_helper.rb
+++ b/actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -180,16 +180,54 @@ module ActionView
form_tag(options[:html].delete(:action) || url_for(options[:url]), options[:html], &block)
end
- # Works like form_remote_tag, but uses form_for semantics.
- def remote_form_for(record_or_name, *args, &proc)
+ # Creates a form that will submit using XMLHttpRequest in the background
+ # instead of the regular reloading POST arrangement and a scope around a
+ # specific resource that is used as a base for questioning about
+ # values for the fields.
+ #
+ # === Resource
+ #
+ # Example:
+ # <% remote_form_for(@post) do |f| %>
+ # ...
+ # <% end %>
+ #
+ # This will expand to be the same as:
+ #
+ # <% remote_form_for :post, @post, :url => post_path(@post), :html => { :method => :put, :class => "edit_post", :id => "edit_post_45" } do |f| %>
+ # ...
+ # <% end %>
+ #
+ # === Nested Resource
+ #
+ # Example:
+ # <% remote_form_for([@post, @comment]) do |f| %>
+ # ...
+ # <% end %>
+ #
+ # This will expand to be the same as:
+ #
+ # <% remote_form_for :comment, @comment, :url => post_comment_path(@post, @comment), :html => { :method => :put, :class => "edit_comment", :id => "edit_comment_45" } do |f| %>
+ # ...
+ # <% end %>
+ #
+ # If you don't need to attach a form to a resource, then check out form_remote_tag.
+ #
+ # See FormHelper#form_for for additional semantics.
+ def remote_form_for(record_or_name_or_array, *args, &proc)
options = args.extract_options!
- case record_or_name
+ case record_or_name_or_array
when String, Symbol
- object_name = record_or_name
+ object_name = record_or_name_or_array
+ when Array
+ object = record_or_name_or_array.last
+ object_name = ActionController::RecordIdentifier.singular_class_name(object)
+ apply_form_for_options!(record_or_name_or_array, options)
+ args.unshift object
else
- object = record_or_name
- object_name = ActionController::RecordIdentifier.singular_class_name(record_or_name)
+ object = record_or_name_or_array
+ object_name = ActionController::RecordIdentifier.singular_class_name(record_or_name_or_array)
apply_form_for_options!(object, options)
args.unshift object
end