diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb
index a7c3b9d..2fd2a21 100644
--- a/actionpack/lib/action_view/helpers/prototype_helper.rb
+++ b/actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -122,12 +122,12 @@ module ActionView
# render :partial.
#
# Examples:
- # # Generates: Delete this post
# link_to_remote "Delete this post", :update => "posts",
# :url => { :action => "destroy", :id => post.id }
#
- # # Generates:
# link_to_remote(image_tag("refresh"), :update => "emails",
# :url => { :action => "list_emails" })
@@ -144,7 +144,7 @@ module ActionView
# error occurs:
#
# Example:
- # # Generates: Delete this post
# link_to_remote "Delete this post",
# :url => { :action => "destroy", :id => post.id },
@@ -171,7 +171,7 @@ module ActionView
# find out the HTTP status, use request.status.
#
# Example:
- # # Generates: hello
# word = 'hello'
# link_to_remote word,
@@ -200,7 +200,7 @@ module ActionView
# adding additional callbacks for specific status codes.
#
# Example:
- # # Generates: hello
# link_to_remote word,
@@ -241,18 +241,21 @@ module ActionView
#
# :with => "'name=' + $('name').value"
#
- # You can generate a link that uses AJAX in the general case, while
- # degrading gracefully to plain link behavior in the absence of
- # JavaScript by setting html_options[:href] to an alternate URL.
+ # link_to_remote automatically sets the href of the generated link
+ # to the value you passed in as :url to degrade gracefully for users
+ # with JavaScript disabled or unavailable. You can override the generated href
+ # by setting html_options[:href] to an alternate URL.
# Note the extra curly braces around the options hash separate
# it as the second parameter from html_options, the third.
#
# Example:
- # link_to_remote "Delete this post",
- # { :update => "posts", :url => { :action => "destroy", :id => post.id } },
- # :href => url_for(:action => "destroy", :id => post.id)
+ # # Generates: hello
+ # link_to_remote "Delete this person",
+ # { :update => "people", :url => person_path(person), :method => :delete },
+ # :href => url_for(:controller => "people", :action => "destroy_without_ajax", :id => person.id)
def link_to_remote(name, options = {}, html_options = nil)
- link_to_function(name, remote_function(options), html_options || options.delete(:html))
+ link_to_function(name, remote_function(options), (html_options || options.delete(:html) || {}).reverse_merge(:href => url_for(options[:url])))
end
# Periodically calls the specified url (options[:url]) every
diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb
index 60b83b4..986d3dd 100644
--- a/actionpack/test/template/prototype_helper_test.rb
+++ b/actionpack/test/template/prototype_helper_test.rb
@@ -67,25 +67,27 @@ class PrototypeHelperTest < PrototypeHelperBaseTest
end
def test_link_to_remote
- assert_dom_equal %(Remote outauthor),
+ assert_dom_equal %(Remote outauthor),
link_to_remote("Remote outauthor", { :url => { :action => "whatnot" }}, { :class => "fine" })
- assert_dom_equal %(Remote outauthor),
+ assert_dom_equal %(Remote outauthor),
link_to_remote("Remote outauthor", :complete => "alert(request.responseText)", :url => { :action => "whatnot" })
- assert_dom_equal %(Remote outauthor),
+ assert_dom_equal %(Remote outauthor),
link_to_remote("Remote outauthor", :success => "alert(request.responseText)", :url => { :action => "whatnot" })
- assert_dom_equal %(Remote outauthor),
+ assert_dom_equal %(Remote outauthor),
link_to_remote("Remote outauthor", :failure => "alert(request.responseText)", :url => { :action => "whatnot" })
- assert_dom_equal %(Remote outauthor),
+ assert_dom_equal %(Remote outauthor),
link_to_remote("Remote outauthor", :failure => "alert(request.responseText)", :url => { :action => "whatnot", :a => '10', :b => '20' })
end
def test_link_to_remote_html_options
- assert_dom_equal %(Remote outauthor),
+ assert_dom_equal %(Remote outauthor),
link_to_remote("Remote outauthor", { :url => { :action => "whatnot" }, :html => { :class => "fine" } })
+ assert_dom_equal %(Remote outauthor),
+ link_to_remote("Remote outauthor", { :url => { :action => "whatnot" }, :html => { :href => "something_else" } })
end
def test_link_to_remote_url_quote_escaping
- assert_dom_equal %(Remote),
+ assert_dom_equal %(Remote),
link_to_remote("Remote", { :url => { :action => "whatnot's" } })
end