Instace variables in templates
justqyx opened this issue · comments
JQ commented
well, while in controller, maybe is
class TestController < ActionCtonroller::Base
def index
@books = Book.all
end
end
and then,
require 'render_anywhere'
class TestStatic
def intialize(book)
@book = book
end
def body
html = render(template: "book/index.html.erb", layout: "application")
p html
edn
end
When run, it raise an error sth about @each is a nil class
Jay OConnor commented
Robbie Clutton commented
You can also pass in locals
render template: 'book/index', layout: 'application', locals: { :@book => book }