Module: Jets::RenderingHelper

Defined in:
lib/jets/overrides/rails/rendering_helper.rb

Instance Method Summary collapse

Instance Method Details

#_get_containing_folder(caller_lines) ⇒ Object

Ugly, going back up the caller stack to find out what view path we are in



20
21
22
23
24
25
# File 'lib/jets/overrides/rails/rendering_helper.rb', line 20

def _get_containing_folder(caller_lines)
  caller_line = caller_lines.find { |l| !l.include?('/gems/') }
  text = caller_line.split(':').first
  # .../fixtures/apps/demo/app/views/posts/index.html.erb
  text.split('/')[-2] # posts
end

#render(options = {}, locals = {}, &block) ⇒ Object

ensure that we always add the controller view name. So when rendering a partial:

<%= render "mypartial" %>

gets turned into:

<%= render "articles/mypartial" %>


7
8
9
10
11
12
13
14
15
16
# File 'lib/jets/overrides/rails/rendering_helper.rb', line 7

def render(options = {}, locals = {}, &block)
  if options.is_a?(String) && !options.include?('/')
    folder = _get_containing_folder(caller)
    partial_name = options # happens to be the partial name
    partial_name = "#{folder}/#{partial_name}"
    options = partial_name
  end

  super(options, locals, &block)
end