Something like this in your application.rb might work...
alias_method_chain(:render, :fallback)
def render_with_falback(*args)
fallback = args.delete[:fallback]
template = args.delete[:template]
if fallback &&
!File.exist?(File.join(RAILS_ROOT,"app/views/#{template}.html.erb")))
template = fallback
end
render_without_fallback(:template => template, args)
end
-Brad
On Tue, Mar 3, 2009 at 3:06 PM, Guyren G Howe <[email protected]> wrote:
>
> On Mar 3, 2009, at 1:12 PM, Matt Aimonetti wrote:
>
> > Why not doing something like
> >
> > string_to_render = a.exists? ? a : b
> > render a
>
> I should have been clearer:
>
> I want to be able to write generic index etc templates, and then
> render those if the template for the current controller doesn't exist.
> So a file structure like this:
>
> foo
> index.html.erb
> edit.html.erb
> bar
> edit.html.erb
> default
> index.html.erb
> edit.html.erb
>
> and then I can say something like:
>
> render_or :template => "#{controller.name}/index", :fallback => '/
> default/index'
>
> I could just do this with an application helper which would catch the
> exception and render the fallback. I'm just wondering if I'm
> reinventing a wheel is all.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---