0.0
No commit activity in last 3 years
No release in over 3 years
Allows a rails format to act as a fallback for another format
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 4.2.5.1
 Project Readme

MimeFallback Build Status

Fix mime-type fallbacks when searching view paths.

Motivation

Let's say you want to render different views for mobile vs desktop. You decided to do it by defining a new Mime::Type alias for text/html. You want to fall back to rendering a html version from a mobile template.

users/show.html.erb:

<h1><%= @user.name %></h1>
<%= image_tag(@user.headshot) %>
<%= render partial: "header", locals: {user: @user} %>

users/show.mobile.erb:

<h1><%= @user.name %></h1>
<%= render partial: "header", locals: {user: @user} %>

You want the both of these partials to render the shared template users/_header.html.erb.

Usage

In your Gemfile:

gem 'mime_fallback'

In your config/initializers/mime_types.rb:

MimeFallback::Type.register_alias "text/html", :mobile, [], :html

That's it.