render default template when requested template is missing in Rails

后端 未结 4 1056
半阙折子戏
半阙折子戏 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:03

    Rails 3.1 automatically looks for files in application/template.html.erb after looking in controller/template.html.erb you can see this in the Exception like so:

    Missing template [controller name]/index, application/index with {:locale=>[:en, :en], :formats=>[:html], :handlers=>[:erb, :coffee, :builder]}. Searched in: * "/path/to/rails_project/app/views" 
    

    so, just put your default templates in app/views/application

提交回复
热议问题