Written by Sean Behan on Sun Jun 17th 2012

If you ever want to render a partial but don't want an error thrown you can either check for the existence of the file first

<%= render :partial => params[:controller]+"/sidebar" if File.exists?(RAILS_ROOT+"/app/views/"+params[:controller]+"/_sidebar.html.erb") %>

or you can catch the error that Rails throws

<%= render :partial => params[:controller]+"/sidebar" rescue nil %>

Tagged with..
#files #nil #partial #render #rescue #Programming #Ruby on Rails

Just finishing up brewing up some fresh ground comments...