From c493370f332715dee0ef795a66e896d7f0471cbe Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Sun, 31 Jan 2010 16:30:21 -0600 Subject: UJS documentation. --- actionpack/lib/action_view/helpers/url_helper.rb | 55 +++++++++++++----------- 1 file changed, 30 insertions(+), 25 deletions(-) (limited to 'actionpack/lib/action_view/helpers/url_helper.rb') diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index e56bfc7bfd..4301647a2c 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -117,8 +117,8 @@ module ActionView # end # # ==== Options - # * :confirm => 'question?' - This will add a JavaScript confirm - # prompt with the question specified. If the user accepts, the link is + # * :confirm => 'question?' - This will allow the unobtrusive JavaScript + # driver to prompt with the question specified. If the user accepts, the link is # processed normally, otherwise no action is taken. # * :method => symbol of HTTP verb - This modifier will dynamically # create an HTML form and immediately submit the form for processing using @@ -195,18 +195,15 @@ module ActionView # link_to "Nonsense search", searches_path(:foo => "bar", :baz => "quux") # # => Nonsense search # - # The three options specific to +link_to+ (:confirm and :method) are used as follows: + # The two options specific to +link_to+ (:confirm and :method) are used as follows: # # link_to "Visit Other Site", "http://www.rubyonrails.org/", :confirm => "Are you sure?" - # # => Visit Other Site - # - # link_to "Delete Image", @image, :confirm => "Are you sure?", :method => :delete - # # => Delete Image + # # => Visit Other Site + # + # link_to("Destroy", "http://www.example.com", :method => :delete, :confirm => "Are you sure?") + # # => Destroy + + # def link_to(*args, &block) if block_given? options = args.first || {} @@ -256,9 +253,11 @@ module ActionView # There are a few special +html_options+: # * :method - Specifies the anchor name to be appended to the path. # * :disabled - Specifies the anchor name to be appended to the path. - # * :confirm - This will add a JavaScript confirm + # * :confirm - This will use the unobtrusive JavaScript driver to # prompt with the question specified. If the user accepts, the link is # processed normally, otherwise no action is taken. + # * :remote - If set to true, will allow the Unobtrusive JavaScript drivers to control the + # submit behaviour. By default this behaviour is an ajax submit. # # ==== Examples # <%= button_to "New", :action => "new" %> @@ -266,15 +265,27 @@ module ActionView # #
# # " # - # button_to "Delete Image", { :action => "delete", :id => @image.id }, - # :confirm => "Are you sure?", :method => :delete + # + # <%= button_to "Delete Image", { :action => "delete", :id => @image.id }, + # :confirm => "Are you sure?", :method => :delete %> # # => "
# #
# # - # # + # # # #
# #
" + # + # + # <%= button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?', + # :method => "delete", :remote => true, :disable_with => 'loading...') %> + # # => "
+ # #
+ # # + # # + # #
+ # #
" + # # + def button_to(name, options = {}, html_options = {}) html_options = html_options.stringify_keys convert_boolean_attributes!(html_options, %w( disabled )) @@ -567,14 +578,8 @@ module ActionView method, href = html_options.delete("method"), html_options['href'] - if confirm && method - add_confirm_to_attributes!(html_options, confirm) - add_method_to_attributes!(html_options, method) - elsif confirm - add_confirm_to_attributes!(html_options, confirm) - elsif method - add_method_to_attributes!(html_options, method) - end + add_confirm_to_attributes!(html_options, confirm) if confirm + add_method_to_attributes!(html_options, method) if method html_options["data-url"] = options[:url] if options.is_a?(Hash) && options[:url] -- cgit v1.2.3