Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 41 lines (29 sloc) 2.211 kb
2ad42b0 Rob Cameron Added readme, bumped version to 0.1.0
authored
1 ## The Problem
2
3 Let's say you're going to start building a mobile version of your site. You use something like
b2f981c Rob Cameron Updated README
authored
4 [mobile fu](https://github.com/brendanlim/mobile-fu) which gives you a new format, `:mobile`, which
2ad42b0 Rob Cameron Added readme, bumped version to 0.1.0
authored
5 is automatically set if a request comes in from a mobile device.
6
7 All you need to do to start serving your mobile pages is to create a `.mobile` version of your views:
8
9 index.html.erb -> index.mobile.erb
10
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.
15
16 ## The Solution
17
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 `index.mobile.erb` 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`).
23
24 Enjoy!
87a8d76 Rob Cameron Updated README with caveats
authored
25
26 ## Caveats
27
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 Rob Cameron Update Gemfile dependency to allow 3.0.0 but still not 3.1
authored
34
35 ## Compatability
36
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.