rwz / nestive

A Better Nested Inheritable Layouts Plugin for Rails
MIT License
236 stars 31 forks source link

no implicit conversion of nil into String #19

Open firedev opened 9 years ago

firedev commented 9 years ago

Just tried to use nestive with Rails 4.2, here is a sample admin.html.erb:

<%=  extends :application do %>
  <% purge :menus %>
<% end %>

It blows up with

TypeError - no implicit conversion of nil into String:
  nestive (0.6.0) lib/nestive/layout_helper.rb:92:in `extends'
firedev commented 9 years ago
@view_flow.get(:layout).replace capture(&block)
TypeError: no implicit conversion of nil into String

capture(&block) returns nil, but the block is correct

block.call
=> [:menus]
fractaledmind commented 8 years ago

So, I don't yet have a solution or an understanding of what precisely is going on, but I have found that I can "fix" this problem by ensuring there are newlines at the end of the block. So, for your example, try this:

<%=  extends :application do %>
  <% purge :menus %>

<% end %>
rwz commented 8 years ago

Interesting. Could you a write a spec reproducing the problem?

rwz commented 8 years ago

I'll try to take a look later today. I think I have an idea what might be going on there and what would be the easiest way to fix it.

fractaledmind commented 8 years ago

I found a simple solution: capture(&block).to_s

fractaledmind commented 8 years ago

It seems that the way the log works, when you initially capture the &block, nothing has been rendered yet, so it is nil. It is only after the file has been rendered (a few lines later) that things start to happen.

I can definitely write a spec to reproduce tho.

jjercx commented 6 years ago

Is it solved? I have the same problem @fractaledmind pointed. (Rails 5.1 btw)

This causes TypeError. no implicit conversion of nil into String

<%= extends :app do %>
  <%= replace :content do %>
    <div class="main main-raised">

      <%= flash_messages %>
      <div class="flash"></div>

      <div class="container">
        <%= yield %>
      </div>
    </div>
  <% end %>
<% end %>

This works:

<%= extends :app do %>
  <%= replace :content do %>
    <div class="main main-raised">

      <%= flash_messages %>
      <div class="flash"></div>

      <div class="container">
        <%= yield %>
      </div>
    </div>
  <% end %>

<% end %>