render default template when requested template is missing in Rails

后端 未结 4 996
半阙折子戏
半阙折子戏 2021-01-19 04:19

For a plugin I want to hack the following feature into Rails:

When a (partial) template does not exist (regardless of the format) I want to render a default template

4条回答
  •  无人共我
    2021-01-19 05:09

    Solution 2:

    Use 'rescue_from' in ApplicationController

    
    
    class ApplicationController > ActionController::Base
      rescue_from ActionView::MissingTemplate do |exception|
        # use exception.path to extract the path information
        # This does not work for partials
      end
    end
    
    
    
    

    Drawback: does not work for partials.

提交回复
热议问题