aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-03-22 12:33:47 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-03-22 12:33:47 +0000
commit4e60fe3ef3474834a9880f3cdd2a47f8efa99bc5 (patch)
treeacdd26f036976ecb3ded5adaf4b99c76f52cc899 /actionpack
parente1ce18020e1c23c148060ec2180dc0ed794be06e (diff)
downloadrails-4e60fe3ef3474834a9880f3cdd2a47f8efa99bc5.tar.gz
rails-4e60fe3ef3474834a9880f3cdd2a47f8efa99bc5.tar.bz2
rails-4e60fe3ef3474834a9880f3cdd2a47f8efa99bc5.zip
Added documentation and fixed an ajax bug
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@974 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG6
-rw-r--r--actionpack/lib/action_view/helpers/javascript_helper.rb19
-rw-r--r--actionpack/lib/action_view/helpers/javascripts/prototype.js2
3 files changed, 18 insertions, 9 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 9c90b2830d..6978ddafb9 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,4 +1,4 @@
-*SVN*
+*1.6.0* (22th March, 2005)
* Added a JavascriptHelper and accompanying prototype.js library that opens the world of Ajax to Action Pack with a large array of options for dynamically interacting with an application without reloading the page #884 [Sam Stephenson/David]
@@ -13,11 +13,11 @@
...
if @something.save
# will redirect, use flash
- flash['message'] = 'Save successful'
+ flash[:message] = 'Save successful'
redirect_to :action => 'list'
else
# no redirect, message is for current action, use flash.now
- flash.now['message'] = 'Save failed, review'
+ flash.now[:message] = 'Save failed, review'
render_action 'edit'
end
end
diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb
index 2e169b0f62..99b2fc1166 100644
--- a/actionpack/lib/action_view/helpers/javascript_helper.rb
+++ b/actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -2,11 +2,16 @@ require File.dirname(__FILE__) + '/tag_helper'
module ActionView
module Helpers
- # You must call <%= define_javascript_functions %> in your application,
- # or copy the included Javascript libraries into your application's
- # public/javascripts/ directory, before using these helpers.
- module JavascriptHelper
-
+ # Provides a set of helpers for calling Javascript functions and, most importantly, to call remote methods using what has
+ # been labelled Ajax[http://www.adaptivepath.com/publications/essays/archives/000385.php]. This means that you can call
+ # actions in your controllers without reloading the page, but still update certain parts of it using injections into the
+ # DOM. The common use case is having a form that adds a new element to a list without reloading the page.
+ #
+ # To be able to use the Javascript helpers, you must either call <%= define_javascript_functions %> (which returns all
+ # the Javascript support functions in a <script> block) or reference the Javascript library using
+ # <%= javascript_include_tag "prototype" %> (which looks for the library in /javascripts/prototype.js). The latter is
+ # recommended as the browser can then cache the library instead of fetching all the functions anew on every request.
+ module JavascriptHelper
unless const_defined? :CALLBACKS
CALLBACKS = [:uninitialized, :loading, :loaded, :interactive, :complete]
JAVASCRIPT_PATH = File.join(File.dirname(__FILE__), 'javascripts')
@@ -63,6 +68,10 @@ module ActionView
link_to_function(name, remote_function(options), html_options)
end
+ # Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular
+ # reloading POST arrangement. Even though it's using Javascript to serialize the form elements, the form submission
+ # will work just like a regular submission as viewed by the receiving side (all elements available in @params).
+ # The options for specifying the target with :url and defining callbacks is the same as link_to_remote.
def form_remote_tag(options = {})
options[:form] = true
diff --git a/actionpack/lib/action_view/helpers/javascripts/prototype.js b/actionpack/lib/action_view/helpers/javascripts/prototype.js
index b998985235..5f2f9edb9c 100644
--- a/actionpack/lib/action_view/helpers/javascripts/prototype.js
+++ b/actionpack/lib/action_view/helpers/javascripts/prototype.js
@@ -288,7 +288,7 @@ Form.Element.Serializers = {
select: function(element) {
var index = element.selectedIndex;
- return [element.name, element.options[index].value];
+ return [element.name, (index >= 0) ? element.options[index].value : ''];
}
}