I also struggled with this. This is the method I ended up with:
<%= render :partial => "#{dynamic_partial}" rescue nil %>
Basically, if partial does not exist, do nothing. Would you like to print something if the partial part is missing?
Edit 1: Oh, I do not understand understanding. You said you want to do something else. In this case, how about this?
<%= render :partial => "#{dynamic_partial}" rescue render :partial => 'partial_that_actually_exists' %>
or
<%= render :partial => "#{dynamic_partial}" rescue "Can't show this data!" %>
Edit 2:
Alternative: checking for a partial file:
<%= render :partial => "#{dynamic_partial}" if File.exists?(Rails.root.join("app", "views", params[:controller], "_#{dynamic_partial}.html.erb")) %>
Jeff Aug 24 '10 at 18:06 2010-08-24 18:06
source share