Using ActionView free style

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?

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?

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

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

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?

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?

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”

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.