# Eruby cutting off top / binding issue

**URL:** <https://www.ruby-forum.com/t/eruby-cutting-off-top-binding-issue/121921>\
**Category:** Ruby\
**Created:** [December 2, 2007, 10:32pm UTC](https://www.ruby-forum.com/t/eruby-cutting-off-top-binding-issue/121921 "2007-12-02T22:32:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [December 2, 2007, 10:32pm UTC](https://www.ruby-forum.com/t/eruby-cutting-off-top-binding-issue/121921/1 "2007-12-02T22:32:49Z")

</div>

I’m trying to use ERB bound to a controlled context, and it’s failing  
when it build a template within another template.  
If you have any insights about this please let me know. I’m simply at  
a loss.

This is a minimal model of the problem I’m having:

require ‘erb’

class Context

```
def initialize(page)
  @page = page
end

def render(*a)
  @page.render(*a)
end

```

end

class Page

```
def initialize
  @context = Context.new(self)
  @binding = @context.instance_eval{ binding }
end

def in1
  %{
    WAY UP HERE
    <%= render('in2') %>
    WAY DOWN HERE
  }
end

def in2
  %{
    RIGHT UP HERE
    <%= render('in3') %>
    RIGHT DOWN HERE
  }
end

def in3
  "IN THE MIDDLE"
end

def render(var)
  input = eval(var)
  template = ERB.new(input)
  template.result(@binding)
end

```

end

puts Page.new.render(‘in1’)

I’m getting:

IN THE MIDDLE  
RIGHT DOWN HERE

```
    WAY DOWN HERE

```

Instead of the expected:

```
  WAY UP HERE

  RIGHT UP HERE
  IN THE MIDDLE
  RIGHT DOWN HERE

  WAY DOWN HERE

```

Why is it cutting off the top? It makes now sense. If I remove the  
context by changing to:

```
  template.result(binding)

```

Then it works fine.

T.
