aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2013-12-03 15:14:49 -0800
committerJeremy Kemper <jeremy@bitsweat.net>2013-12-03 15:14:49 -0800
commit501acab943cdc3a5ac389cfd9b39dc34d3ca86fb (patch)
treed20232cd9ea12691bb126e48855ed8ced15c6371 /guides/source
parent4d648819c5662f375b8ca431a14511ae6a97a29c (diff)
parenteb0402d512a1fb4e65a4d8d3dab3684e9f136b34 (diff)
downloadrails-501acab943cdc3a5ac389cfd9b39dc34d3ca86fb.tar.gz
rails-501acab943cdc3a5ac389cfd9b39dc34d3ca86fb.tar.bz2
rails-501acab943cdc3a5ac389cfd9b39dc34d3ca86fb.zip
Merge pull request #12977 from strzalek/action-pack-variants
Action Pack Variants
Diffstat (limited to 'guides/source')
-rw-r--r--guides/source/4_1_release_notes.md33
1 files changed, 33 insertions, 0 deletions
diff --git a/guides/source/4_1_release_notes.md b/guides/source/4_1_release_notes.md
index de29b2e58e..0e3e2037ff 100644
--- a/guides/source/4_1_release_notes.md
+++ b/guides/source/4_1_release_notes.md
@@ -3,6 +3,7 @@ Ruby on Rails 4.1 Release Notes
Highlights in Rails 4.1:
+* Variants
* Action View extracted from Action Pack
These release notes cover only the major changes. To know about various bug
@@ -27,6 +28,38 @@ guide.
Major Features
--------------
+* Variants
+
+ We often want to render different html/json/xml templates for phones,
+ tablets, and desktop browsers. Variants make it easy.
+
+ The request variant is a specialization of the request format, like :tablet,
+ :phone, or :desktop.
+
+ You can set the variant in a before_action:
+
+ ```ruby
+ request.variant = :tablet if request.user_agent =~ /iPad/
+ ```
+
+ Respond to variants in the action just like you respond to formats:
+
+ ```ruby
+ respond_to do |format|
+ format.html do |html|
+ html.tablet # renders app/views/projects/show.html+tablet.erb
+ html.phone { extra_setup; render ... }
+ end
+ end
+ ```
+
+ Provide separate templates for each format and variant:
+
+ ```
+ app/views/projects/show.html.erb
+ app/views/projects/show.html+tablet.erb
+ app/views/projects/show.html+phone.erb
+ ```
Documentation
-------------