2

据说安装erubis很简单:

gem install erubis

# And in environment.rb:
require 'erubis/helpers/rails_helper'

但我还没有发现是这样的。请注意,我的代码中没有明显的错误;它与 ERB 一起运行得很好。

  1. 我把这条线放在哪里?包含后boot.rb立即无法启动服务器,并且在文件末尾我收到意外的 nil 对象错误(nil.controller)。哪里最好?
  2. 与给定版本是否存在已知冲突?
  3. 有什么解决方法可以让 erubis 发挥作用吗?
4

3 回答 3

1

The latest Erubis (2.6.4) and Rails 2.2 (and 2.3) are still not compatible. The main issue is that the generated ruby code from Erubis uses "_buf" as the buffer variable and Rails 2.2 and 2.3 require "@output_buffer" to be used.

The reason for "@output_buffer" to be used is that ActionView helpers like CaptureHelper are designed around "@output_buffer" being the primary buffer in the generated code.

I have created a gem called elkinsware-erubis_rails_helper that fixes these issues and allows Erubis and Rails 2.3 (for sure but it should work for 2.2).

In your environment.rb file add:

 config.gem 'erubis' , :version => '2.6.4'
 config.gem 'elkinsware-erubis_rails_helper', :lib => 'erubis_rails_helper', :source => 'http://gems.github.com'

And then you can add a config/initializers/erubis_config.rb where you can adjust the Erubis/Rails options.

 #Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby # or Erubis::FastEruby
 #Erubis::Helpers::RailsHelper.init_properties = {}
 #Erubis::Helpers::RailsHelper.show_src = false
 #Erubis::Helpers::RailsHelper.preprocessing = true

The source is at http://github.com/elkinsware/erubis_rails_helper/tree/master

Let me know if you have any issues with the gem.

于 2009-06-18T11:37:00.170 回答
1
  1. Either put it on the bottom or environment.rb, or put it in an initializer (config/initializers/anything.rb). When you put it before the Rails::Initializer block, the rails environment hasn't fully loaded yet, and erubis/helpers/rails_helpers seems to assume a fully loaded Rails environment.
  2. I have never used erubis, so I can't answer that.
  3. Workarounds? See #1, I guess.
于 2008-12-25T09:57:25.183 回答
1

显然这被打破了:

http://kleinptr.wordpress.com/2009/02/04/erubis-and-rails-222/

他们正在修复:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/328613

于 2009-02-23T19:52:56.310 回答