Let's say you're making your Rails application mobile-friendly with Action Pack Variants.
The application has the following directory structure:
app/views ├── layouts │ ├── application.html+mobile.erb │ └── application.html.erb └── projects ├── index.html+mobile.erb ├── index.html.erb └── new.html.erb
In this case, when you set
:mobile, Rails will render templates as follows:
The second behaviour means that you have to prepare mobile versions of every template right away.
However, you couldn't do that when you have so many templates in your application.
actionview-consistent_fallback is a small, but usuful plugin for Action View.
The plugin allows you to fallback to the default layout and partials when there is no variant template corresponding to each request variant.
In the above case,
new.html.erb is rendered with
By the consistent fallback, you can gradually roll out a mobile-version page.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install actionview-consistent_fallback
All you need to do is to load the gem, and then create as many variant templates as you can now :)
You should follow the steps below.
- Fork the repository
- Create a feature branch:
git checkout -b add-new-feature
- Commit your changes:
git commit -am 'Add new feature'
- Push the branch:
git push origin add-new-feature
- Send us a pull request
The gem is available as open source under the terms of the MIT License.