Module: RenderWithMissingTemplate::ActionController::InstanceMethods

Defined in:
lib/render_with_missing_template/action_controller.rb

Instance Method Summary collapse

Instance Method Details

#render_with_defaults(*args) ⇒ Object

ActionController::render overload is needed because ActionController::render have different signature and accepts different options.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/render_with_missing_template/action_controller.rb', line 12

def render_with_defaults(*args)
  options = args.extract_options!
  defaults = options.delete(:if_missing)
  unless defaults.nil?
    begin
      # Ac is important:
      #   index/index.html.erb
      #     render "missing_partial" # MissingTemplate is raised here
      #
      #   index_controller.rb
      #     def index
      #       render :if_missing => {:template => "layouts/create_me"} # And caught here
      #     end
      #
      # In fact MissingTemplate in a view should not be caught by controller because controller's template exists, but
      # it have errors inside. :nested option tells nested render to raise MissingTemplateContrainer exception instead of
      # raising MissingTemplate. This exception means that action template is resolved, but some of nested partials are not.
      render_without_defaults(options.merge(:nested => true))
    rescue MissingTemplateContainer => e
      unless defaults == false
        defaults = options.merge(defaults)
        render_without_defaults(defaults)
      else
        render_without_defaults(:nothing => true)
      end
    end
  else
    render_without_defaults options
  end
end