aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_view/helpers/form_tag_helper.rb15
-rw-r--r--actionpack/lib/action_view/helpers/prototype_helper.rb9
-rw-r--r--actionpack/lib/action_view/helpers/tag_helper.rb4
3 files changed, 23 insertions, 5 deletions
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index 8d6d8e99ea..ca6d9e1841 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -12,6 +12,19 @@ module ActionView
# Starts a form tag that points the action to an url configured with <tt>url_for_options</tt> just like
# ActionController::Base#url_for. The method for the form defaults to POST.
#
+ # Examples:
+ # * <tt>form_tag('/posts') => <form action="/posts" method="post"></tt>
+ # * <tt>form_tag('/posts/1', :method => :put) => <form action="/posts/1" method="put"></tt>
+ # * <tt>form_tag('/upload', :multipart => true) => <form action="/upload" method="post" enctype="multipart/form-data"></tt>
+ #
+ # ERb example:
+ # <% form_tag '/posts' do -%>
+ # <div><%= submit_tag 'Save' %></div>
+ # <% end -%>
+ #
+ # Will output:
+ # <form action="/posts" method="post"><div><input type="submit" name="submit" value="Save" /></div></form>
+ #
# Options:
# * <tt>:multipart</tt> - If set to true, the enctype is set to "multipart/form-data".
# * <tt>:method</tt> - The method to use when submitting the form, usually either "get" or "post".
@@ -31,7 +44,7 @@ module ActionView
html_options["method"] = "post"
else
html_options["method"] = "post"
- method_tag = tag(:input, :type => "hidden", :name => "_method", :value => method)
+ method_tag = content_tag(:div, tag(:input, :type => "hidden", :name => "_method", :value => method), :style => 'margin:0;padding:0')
end
if block_given?
diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb
index 1b4d2e71d8..f26b673fbc 100644
--- a/actionpack/lib/action_view/helpers/prototype_helper.rb
+++ b/actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -164,7 +164,12 @@ module ActionView
#
# By default the fall-through action is the same as the one specified in
# the :url (and the default method is :post).
- def form_remote_tag(options = {})
+ #
+ # form_remote_tag also takes a block, like form_tag:
+ # <% form_remote_tag :url => '/posts' do -%>
+ # <div><%= submit_tag 'Save' %></div>
+ # <% end -%>
+ def form_remote_tag(options = {}, &block)
options[:form] = true
options[:html] ||= {}
@@ -172,7 +177,7 @@ module ActionView
(options[:html][:onsubmit] ? options[:html][:onsubmit] + "; " : "") +
"#{remote_function(options)}; return false;"
- form_tag(options[:html].delete(:action) || url_for(options[:url]), options[:html])
+ form_tag(options[:html].delete(:action) || url_for(options[:url]), options[:html], &block)
end
# Works like form_remote_tag, but uses form_for semantics.
diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb
index 8b8c7b491c..219888adb5 100644
--- a/actionpack/lib/action_view/helpers/tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/tag_helper.rb
@@ -20,9 +20,9 @@ module ActionView
# <tt><div class="strong"><p>Hello world!</p></div></tt>
#
# ERb example:
- # <% content_tag :div, :class => "strong" %>
+ # <% content_tag :div, :class => "strong" do -%>
# Hello world!
- # <% end %>
+ # <% end -%>
#
# Will output:
# <div class="strong"><p>Hello world!</p></div>