# Using ActionView free style

**URL:** <https://www.ruby-forum.com/t/using-actionview-free-style/98370>\
**Category:** Rails\
**Created:** [July 14, 2006, 7:20am UTC](https://www.ruby-forum.com/t/using-actionview-free-style/98370 "2006-07-14T07:20:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 14, 2006, 7:20am UTC](https://www.ruby-forum.com/t/using-actionview-free-style/98370/1 "2006-07-14T07:20:09Z")

</div>

ActionView is a very useful class, in its own right. But, calling it by  
itself causes a weird crash, exiting Ruby, without even raising an  
exception!

ruby script/runner “begin; av = ActionView::Base.new; av.render(:inline  
=\> ‘Hi!’); rescue =\> e; puts e; end”

just crashes Ruby.

Same with render(:file =\> ‘template.rhtml’)

Why is this?

What is the proper way to use ActionView to render a template?

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 14, 2006, 7:28am UTC](https://www.ruby-forum.com/t/using-actionview-free-style/98370/2 "2006-07-14T07:28:40Z")

</div>

Oops. Forgot the “puts”.

Works fine when rendering inline templates. But I can’t get the same  
syntax to work to render :file =\> filename.

Robert J. wrote:

> ActionView is a very useful class, in its own right. But, calling it by  
> itself causes a weird crash, exiting Ruby, without even raising an  
> exception!
> 
> ruby script/runner “begin; av = ActionView::Base.new; av.render(:inline  
> =\> ‘Hi!’); rescue =\> e; puts e; end”
> 
> just crashes Ruby.
> 
> Same with render(:file =\> ‘template.rhtml’)
> 
> Why is this?
> 
> What is the proper way to use ActionView to render a template?

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 14, 2006, 5:57pm UTC](https://www.ruby-forum.com/t/using-actionview-free-style/98370/3 "2006-07-14T17:57:48Z")

</div>

I did more testing, and think I may have found a bug:

You can use ActionView freestyly to do compile\_and\_render\_template -  
but, if you give it a file to load itself, Ruby crashes. No exception,  
no error, just the intepreter exits.

(I’m running Windows. Perhaps on Linux it would dump core?).

Example:

av = ActionView::Base.new  
t = “/path/to/template/file.rhtml”  
av.render\_file(t, false)

# crash

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 15, 2006, 12:32pm UTC](https://www.ruby-forum.com/t/using-actionview-free-style/98370/4 "2006-07-15T12:32:34Z")

</div>

Robert J. wrote on 14.07.2006 23:32:

> > av = ActionView::Base.new  
> > t = “/path/to/template/file.rhtml”  
> > av.render\_file(t, false)
> > 
> > # crash
> 
> What does everyone else get? A crash, or does it work?

With the above code an error:

test.rb(main):008:0\* av = ActionView::Base.new()  
=\> #\<ActionView::Base:0xb7a793f8 @assigns={}, @base\_path=nil,  
@logger=nil, @assigns\_added=nil, @controller=nil\>  
test.rb(main):009:0\> t = “test.rhtml”  
=\> “test.rhtml”  
test.rb(main):010:0\> av.render\_file(t, false)  
Exception `TypeError’ at  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action\_view/base.rb:477

- can’t convert nil into String

But with a set base\_path it works:

test.rb(main):008:0\* av = ActionView::Base.new(’.’)  
=\> #\<ActionView::Base:0xb7ae1bac @assigns={}, @base\_path=".",  
@logger=nil, @assigns\_added=nil, @controller=nil\>  
test.rb(main):009:0\> t = “test.rhtml”  
=\> “test.rhtml”  
test.rb(main):010:0\> av.render\_file(t, false)  
=\> “\n\n”

Hope it helps…

Markus

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 14, 2006, 11:32pm UTC](https://www.ruby-forum.com/t/using-actionview-free-style/98370/5 "2006-07-14T23:32:57Z")

</div>

Robert J. wrote:

> I did more testing, and think I may have found a bug:
> 
> You can use ActionView freestyly to do compile\_and\_render\_template -  
> but, if you give it a file to load itself, Ruby crashes. No exception,  
> no error, just the intepreter exits.
> 
> (I’m running Windows. Perhaps on Linux it would dump core?).
> 
> Example:
> 
> av = ActionView::Base.new  
> t = “/path/to/template/file.rhtml”  
> av.render\_file(t, false)
> 
> # crash

What does everyone else get? A crash, or does it work?

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 17, 2006, 2:53am UTC](https://www.ruby-forum.com/t/using-actionview-free-style/98370/6 "2006-07-17T02:53:02Z")

</div>

Robert J. wrote:

> Must be a windows issue - I still get a Ruby crash - not even an  
> exception, the intepreter just crashes. What OS are you running?
> 
> Markus K. wrote:
> 
> > But with a set base\_path it works:
> > 
> > test.rb(main):008:0\* av = ActionView::Base.new(’.’)  
> > =\> #\<ActionView::Base:0xb7ae1bac @assigns={}, @base\_path=".",  
> > @logger=nil, @assigns\_added=nil, @controller=nil\>  
> > test.rb(main):009:0\> t = “test.rhtml”  
> > =\> “test.rhtml”  
> > test.rb(main):010:0\> av.render\_file(t, false)  
> > =\> “\n\n”

Can someone else with ruby on Windows try running this and see if Ruby  
crashes for them?

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 16, 2006, 4:36pm UTC](https://www.ruby-forum.com/t/using-actionview-free-style/98370/7 "2006-07-16T16:36:12Z")

</div>

Must be a windows issue - I still get a Ruby crash - not even an  
exception, the intepreter just crashes. What OS are you running?

Markus K. wrote:

> But with a set base\_path it works:
> 
> test.rb(main):008:0\* av = ActionView::Base.new(’.’)  
> =\> #\<ActionView::Base:0xb7ae1bac @assigns={}, @base\_path=".",  
> @logger=nil, @assigns\_added=nil, @controller=nil\>  
> test.rb(main):009:0\> t = “test.rhtml”  
> =\> “test.rhtml”  
> test.rb(main):010:0\> av.render\_file(t, false)  
> =\> “\n\n”

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [September 3, 2006, 10:36pm UTC](https://www.ruby-forum.com/t/using-actionview-free-style/98370/8 "2006-09-03T22:36:59Z")

</div>

Robert J. wrote:

> Robert J. wrote:
> 
> > Must be a windows issue - I still get a Ruby crash - not even an  
> > exception, the intepreter just crashes. What OS are you running?
> > 
> > Markus K. wrote:
> > 
> > > But with a set base\_path it works:
> > > 
> > > test.rb(main):008:0\* av = ActionView::Base.new(’.’)  
> > > =\> #\<ActionView::Base:0xb7ae1bac @assigns={}, @base\_path=".",  
> > > @logger=nil, @assigns\_added=nil, @controller=nil\>  
> > > test.rb(main):009:0\> t = “test.rhtml”  
> > > =\> “test.rhtml”  
> > > test.rb(main):010:0\> av.render\_file(t, false)  
> > > =\> “\n\n”
> 
> Can someone else with ruby on Windows try running this and see if Ruby  
> crashes for them?

I’m getting this very same problem. Basically, when ActionView tries to  
raise an exception because it can’t find the file to render, if it was  
invoked freestyle, it crashes rather than produce an error. Only in  
Windows though.
