actionview-consistent_fallback
Motivation
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 request.variant
to :mobile
, Rails will render templates as follows:
-
projects#index
:index.html+mobile.erb
withapplication.html+mobile.erb
-
projects#new
:new.html.erb
withapplication.html+mobile.erb
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.
Solution
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 application.html.erb
for mobile
variant.
By the consistent fallback, you can gradually roll out a mobile-version page.
Installation
Add this line to your application's Gemfile:
gem 'actionview-consistent_fallback'
And then execute:
$ bundle
Or install it yourself as:
$ gem install actionview-consistent_fallback
Usage
All you need to do is to load the gem, and then create as many variant templates as you can now :)
Contributing
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
License
The gem is available as open source under the terms of the MIT License.