No commit activity in last 3 years
No release in over 3 years
Extends rails render method to render default template when expected template is missing
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 3.0.0
 Project Readme

render_with_missing_template¶ ↑

Installation¶ ↑

Rails 3 only. Add following line to your Gemfile:

gem 'render_with_missing_template'

Examples:¶ ↑

app/controllers/test_controller.rb

def index
  # Renders template layouts/default/index if tests/index is missing
  render :if_missing => {:template => "layouts/default/index"}
end

app/views/index.html.erb

<!-- Renders nothing if "navigation2" is missing --> 
<%= render :partial => "navigation2", :if_missing => false %>

<!-- Renders template "layouts/defaults/navigation" if "navigation2" is missing -->
<%= render :partial => "navigation2", :if_missing => {:template => "layouts/defaults/navigation"} %>

Note¶ ↑

app/controllers/test_controller.rb

def index
  # Renders template layouts/default/index if tests/index is missing
  render :if_missing => {:template => "layouts/default/index"}
end

def index
  # Renders template layouts/default/index if tests/index is missing inside layout 'nowhere'. Render options are merged with default options.
  # Not shure that it is good strategy to merge. May be, option is required.
  render :layout => 'nowhere', :if_missing => {:template => "layouts/default/index"}
end

app/views/index.html.erb

<!-- Raises TemplateMissing because there is no :if_missing option here. --> 
<%= render :partial => "navigation2" %>