No release in over 3 years
Low commit activity in last 3 years
This Action View plugin allows you to fallback to the default layout and partials when there is no variant template corresponding to each request variant.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

< 6, >= 4.1.0
 Project Readme

actionview-consistent_fallback

Gem Version Build Status Code Climate Test Coverage

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 with application.html+mobile.erb
  • projects#new: new.html.erb with application.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.

  1. Fork the repository
  2. Create a feature branch: git checkout -b add-new-feature
  3. Commit your changes: git commit -am 'Add new feature'
  4. Push the branch: git push origin add-new-feature
  5. Send us a pull request

License

The gem is available as open source under the terms of the MIT License.