diff options
author | Neeraj Singh <neerajdotname@gmail.com> | 2010-06-25 14:13:47 -0400 |
---|---|---|
committer | Neeraj Singh <neerajdotname@gmail.com> | 2010-06-25 14:13:47 -0400 |
commit | dd5924d8ca06334898831ffede11efe2c264b5f0 (patch) | |
tree | 9590d51e948bb10ebcdcf68d64e03f9d9da70ea3 /railties/guides/source | |
parent | a2242a608e5c3057ec46ddffdd983d94780f90f6 (diff) | |
download | rails-dd5924d8ca06334898831ffede11efe2c264b5f0.tar.gz rails-dd5924d8ca06334898831ffede11efe2c264b5f0.tar.bz2 rails-dd5924d8ca06334898831ffede11efe2c264b5f0.zip |
added to_xml section for controller
Diffstat (limited to 'railties/guides/source')
-rw-r--r-- | railties/guides/source/action_controller_overview.textile | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/railties/guides/source/action_controller_overview.textile b/railties/guides/source/action_controller_overview.textile index 9d8426b5de..038ca903c1 100644 --- a/railties/guides/source/action_controller_overview.textile +++ b/railties/guides/source/action_controller_overview.textile @@ -338,6 +338,25 @@ end Note that while for session values you set the key to +nil+, to delete a cookie value you should use +cookies.delete(:key)+. +h3. Rendering xml and json data + +ActionController makes it extremely easy to render +xml+ or +json+ data. If you generate a controller using scaffold then your controller would look something like this. + +<ruby> +class UsersController < ApplicationController + def index + @users = User.all + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @users} + end + end +end +</ruby> + +Notice that in the above case code is <tt>render :xml => @users</tt> and not <tt>render :xml => @users.to_xml</tt>. That is because if the input is not string then rails automatically invokes +to_xml+ . + + h3. Filters Filters are methods that are run before, after or "around" a controller action. |