aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/base.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2008-11-01 12:03:49 +0100
committerDavid Heinemeier Hansson <david@loudthinking.com>2008-11-01 12:03:49 +0100
commitcbeac93310a7e95453bea3f2d4551288fd455d07 (patch)
treefed49136581bf2f15b0616139b1e8ff0baed7434 /actionpack/lib/action_controller/base.rb
parent408c7227575e0c395a45605783cade1ba3b51e02 (diff)
downloadrails-cbeac93310a7e95453bea3f2d4551288fd455d07.tar.gz
rails-cbeac93310a7e95453bea3f2d4551288fd455d07.tar.bz2
rails-cbeac93310a7e95453bea3f2d4551288fd455d07.zip
Added render :js for people who want to render inline JavaScript replies without using RJS [DHH]
Diffstat (limited to 'actionpack/lib/action_controller/base.rb')
-rw-r--r--actionpack/lib/action_controller/base.rb24
1 files changed, 23 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index e73fc32c59..09bad569e5 100644
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -801,6 +801,19 @@ module ActionController #:nodoc:
# # Renders "Hello from code!"
# render :text => proc { |response, output| output.write("Hello from code!") }
#
+ # === Rendering XML
+ #
+ # Rendering XML sets the content type to application/xml.
+ #
+ # # Renders '<name>David</name>'
+ # render :xml => {:name => "David"}.to_xml
+ #
+ # It's not necessary to call <tt>to_xml</tt> on the object you want to render, since <tt>render</tt> will
+ # automatically do that for you:
+ #
+ # # Also renders '<name>David</name>'
+ # render :xml => {:name => "David"}
+ #
# === Rendering JSON
#
# Rendering JSON sets the content type to application/json and optionally wraps the JSON in a callback. It is expected
@@ -846,7 +859,12 @@ module ActionController #:nodoc:
# page.visual_effect :highlight, 'user_list'
# end
#
- # === Rendering with status and location headers
+ # === Rendering vanilla JavaScript
+ #
+ # In addition to using RJS with render :update, you can also just render vanilla JavaScript with :js.
+ #
+ # # Renders "alert('hello')" and sets the mime type to text/javascript
+ # render :js => "alert('hello')"
#
# All renders take the <tt>:status</tt> and <tt>:location</tt> options and turn them into headers. They can even be used together:
#
@@ -898,6 +916,10 @@ module ActionController #:nodoc:
response.content_type ||= Mime::XML
render_for_text(xml.respond_to?(:to_xml) ? xml.to_xml : xml, options[:status])
+ elsif js = options[:js]
+ response.content_type ||= Mime::JS
+ render_for_text(js, options[:status])
+
elsif json = options[:json]
json = json.to_json unless json.is_a?(String)
json = "#{options[:callback]}(#{json})" unless options[:callback].blank?