1

I'm building a templating system in Rails and I'm trying to get ERB to render the partial of a partial. Here's what I have so far -

script.rb

file = File.read(Rails.root + "app/views/example/_parent.html.erb")
ERB.new(file).result

_parent.html.erb

<%= render 'example/child', name: 'Jim' %>

_child.html.erb

<p>hello <%= name %></p>

When I run my script I get this error -

NoMethodError: undefined method `render' for main:Object from (erb):1:in `<main>'

I want it to return -

<p>hello Jim</p>

I'm pretty new to the working with ERB under the hood so it might be something easy I'm missing.

Ryan Grush
  • 2,076
  • 3
  • 37
  • 64

0 Answers0