Skip to content


Subversion checkout URL

You can clone with
Download ZIP
100644 41 lines (29 sloc) 2.16 KB
2ad42b0 @cannikin Added readme, bumped version to 0.1.0
1 ## The Problem
3 Let's say you're going to start building a mobile version of your site. You use something like
b2f981c @cannikin Updated README
4 [mobile fu]( which gives you a new format, `:mobile`, which
2ad42b0 @cannikin Added readme, bumped version to 0.1.0
5 is automatically set if a request comes in from a mobile device.
7 All you need to do to start serving your mobile pages is to create a `.mobile` version of your views:
9 index.html.erb ->
11 Great! The only downside is that now you need `.mobile` versions of every view in your site right
12 away. Even worse, you need `.mobile` version of every _partial_ in your site. Sometimes you might
13 just want a new application layout for mobile and let everything else stay just the way it is.
14 Enter Format Fallback.
16 ## The Solution
18 Format Fallback simply tries to get a `.html` version of a view if the initial format lookup fails.
19 So if Rails tries to get `` it will normally throw a `MissingTemplate` error. Now it will
20 switch formats to `.html` and try to get that instead. Then, if `.html` isn't found, you'll get a
21 `MissingTemplate` error (which will, by the way, list the original format that couldn't be found,
22 not `.html`).
24 Enjoy!
87a8d76 @cannikin Updated README with caveats
26 ## Caveats
28 Format Fallback doesn't currently let you provide any options to say, for example, "only fall back
29 to `:html` if `:mobile` isn't found." It will attempt to fall back for *any* template that isn't found.
30 Rails is generally trying to help you by telling you that a given template is missing so that you
31 know you have to go in and add one. Which means if you're working on some new `:csv` versions of your
32 pages but forget to add one, and there is a requisite `:html` version, Rails will now serve the `:html`
33 version automatically. Someone would probably find this in testing, but it's something to be aware of.
26e05e9 @cannikin Update Gemfile dependency to allow 3.0.0 but still not 3.1
35 ## Compatability
37 Right now this gem is locked to Rails > 3.0.0 but < 3.1.0 I'm using Rails 3.0.10 locally and haven't
38 tested against Rails 3.1 yet. I assume that the template lookup code for Rails probably isn't going
39 to change any time soon, but I locked in these versions just in case. If you use this gem, and use it
40 on 3.1.x and it works fine, let me know and I'll update the dependency in the Gemfile.
Something went wrong with that request. Please try again.