Browse files

Expanded :method option in FormTagHelper#form_tag, FormHelper#form_fo…

…r, PrototypeHelper#remote_form_for, PrototypeHelper#remote_form_tag, and PrototypeHelper#link_to_remote to allow for verbs other than GET and POST by automatically creating a hidden form field named _method, which will simulate the other verbs over post [DHH]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4375 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 140a998 commit 2b5894741bdbc4b7e8ba7764eabbcfe33123dbfc @dhh dhh committed May 29, 2006
View
4 actionpack/CHANGELOG
@@ -1,8 +1,6 @@
*SVN*
-* Added :method handling for other verbs to remote_form_tag and remote_form_for [DHH]
-
-* Expanded :method option in FormHelper#form_tag to allow for verbs other than GET and POST by automatically creating a hidden form field named _method, which will simulate the other verbs over post [DHH]
+* Expanded :method option in FormTagHelper#form_tag, FormHelper#form_for, PrototypeHelper#remote_form_for, PrototypeHelper#remote_form_tag, and PrototypeHelper#link_to_remote to allow for verbs other than GET and POST by automatically creating a hidden form field named _method, which will simulate the other verbs over post [DHH]
* Added :method option to UrlHelper#link_to, which allows for using other verbs than GET for the link. This replaces the :post option, which is now deprecated. Example: link_to "Destroy", person_url(:id => person), :method => :delete [DHH]
View
6 actionpack/lib/action_view/helpers/javascripts/prototype.js
@@ -669,6 +669,12 @@ Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
var parameters = this.options.parameters || '';
if (parameters.length > 0) parameters += '&_=';
+ /* Simulate other verbs over post */
+ if (this.options.method != 'get' && this.options.method != 'post') {
+ parameters += (parameters.length > 0 ? '&' : '') + '_method=' + this.options.method
+ this.options.method = 'post'
+ }
+
try {
this.url = url;
if (this.options.method == 'get' && parameters.length > 0)
View
8 actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -39,7 +39,7 @@ module PrototypeHelper
# XMLHttpRequest. The result of that request can then be inserted into a
# DOM object whose id can be specified with <tt>options[:update]</tt>.
# Usually, the result would be a partial prepared by the controller with
- # either render_partial or render_partial_collection.
+ # render :partial.
#
# Examples:
# link_to_remote "Delete this post", :update => "posts",
@@ -60,6 +60,12 @@ module PrototypeHelper
# influence how the target DOM element is updated. It must be one of
# <tt>:before</tt>, <tt>:top</tt>, <tt>:bottom</tt>, or <tt>:after</tt>.
#
+ # The method used is by default POST. You can also specify GET or you
+ # can simulate PUT or DELETE over POST. All specified with <tt>options[:method]</tt>
+ #
+ # Example:
+ # link_to_remote "Destroy", person_url(:id => person), :method => :delete
+ #
# By default, these remote requests are processed asynchronous during
# which various JavaScript callbacks can be triggered (for progress
# indicators and the likes). All callbacks get access to the

0 comments on commit 2b58947

Please sign in to comment.