我刚刚开始写自己的宝石。其中一个需要gnuplot gem,如下所示:
module Rocker
require "gnuplot"
# ... module code here ...
end
它工作得很好,直到我在我的一个Rails项目中将我的gem添加到config / environment.rb。然后,不会加载单个页面。我得到这样的错误:
Matrices中的TypeError#show
显示 应用程序/视图/基质/ _detail.html.erb 第13行提出的地方:
不能重复NilClass
跟踪继续,但它没用。我很清楚,gnuplot正在制造某种冲突。
gems有相同的config / environment.rb吗?我知道你不应该在宝石中require "rubygems"
了。将宝石提供给我的自定义宝石的正确方法是什么?
(是的,我怀疑我可以在我的Rails应用程序中添加gnuplot作为依赖项,但是我的gem不会通过它的单元测试。)
要求完整跟踪。首先,我使用的是acts_as_commentable插件,当需要gnuplot时,会出错:
$ script/server
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3002
/home/jwoods/NetBeansProjects/crossval/vendor/rails/activerecord/lib/active_record/base.rb:1959:in `method_missing': undefined local variable or method `acts_as_commentable' for #<Class:0xb6889710> (NameError)
from /home/jwoods/NetBeansProjects/crossval/app/models/matrix.rb:98
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /home/jwoods/NetBeansProjects/crossval/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /home/jwoods/NetBeansProjects/crossval/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /home/jwoods/NetBeansProjects/crossval/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /usr/lib/ruby/1.8/gnuplot.rb:6
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /home/jwoods/NetBeansProjects/crossval/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /home/jwoods/NetBeansProjects/crossval/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /home/jwoods/NetBeansProjects/crossval/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /var/lib/gems/1.8/gems/rocker-0.1.2/lib/rocker.rb:10
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /home/jwoods/NetBeansProjects/crossval/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /home/jwoods/NetBeansProjects/crossval/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /home/jwoods/NetBeansProjects/crossval/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /home/jwoods/NetBeansProjects/crossval/config/../vendor/rails/railties/lib/rails/gem_dependency.rb:208:in `load'
from /home/jwoods/NetBeansProjects/crossval/config/../vendor/rails/railties/lib/initializer.rb:307:in `load_gems'
from /home/jwoods/NetBeansProjects/crossval/config/../vendor/rails/railties/lib/initializer.rb:307:in `each'
from /home/jwoods/NetBeansProjects/crossval/config/../vendor/rails/railties/lib/initializer.rb:307:in `load_gems'
from /home/jwoods/NetBeansProjects/crossval/config/../vendor/rails/railties/lib/initializer.rb:164:in `process'
from /home/jwoods/NetBeansProjects/crossval/config/../vendor/rails/railties/lib/initializer.rb:113:in `send'
from /home/jwoods/NetBeansProjects/crossval/config/../vendor/rails/railties/lib/initializer.rb:113:in `run'
from /home/jwoods/NetBeansProjects/crossval/config/environment.rb:9
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /home/jwoods/NetBeansProjects/crossval/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /home/jwoods/NetBeansProjects/crossval/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /home/jwoods/NetBeansProjects/crossval/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
from /home/jwoods/NetBeansProjects/crossval/vendor/rails/railties/lib/commands/server.rb:84
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from script/server:11
如果我从class Matrix
注释掉acts_as_commentable行,则服务器启动。但是当我尝试加载其中一个Matrix视图时,我得到另外两个跟踪:
ActionView::TemplateError (A copy of Experiment has been removed from the module tree but is still active!) on line #19 of app/views/matrices/index.html.erb:
16: <li>cells: <%= predict_matrix.cells.count %></li>
17: <li>density: <%= fractional_density(predict_matrix) %></li>
18: <li>folds: <%= predict_matrix.children.count %> / <%= predict_matrix.has_grandchildren? ? 2 : 1 %></li>
19: <li><%= experiments_progress_bar(predict_matrix) %></li>
20: </ul>
21:
22: <%= link_to 'New experiment', new_matrix_experiment_path(predict_matrix) %>
app/helpers/matrices_helper.rb:104:in `experiments_progress_bar'
app/views/matrices/index.html.erb:19
app/views/matrices/index.html.erb:9:in `each'
app/views/matrices/index.html.erb:9
app/views/matrices/index.html.erb:4:in `each_pair'
app/views/matrices/index.html.erb:4
app/controllers/matrices_controller.rb:83:in `index'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
Rendered rescues/_trace (36.1ms)
Rendered rescues/_request_and_response (0.2ms)
Rendering rescues/layout (internal_server_error)
和这一个:
ActionView::TemplateError (can't dup NilClass) on line #13 of app/views/matrices/_detail.html.erb:
10: <li class="submatrix_info">Submatrices
11: <ul>
12: <% matrix.children.each do |child| %>
13: <li><%= link_to child.id, matrix_path(child), :class => "submatrix_link" %><%= experiments_progress_bar(child) %></li>
14: <% end %>
15: </ul>
16: </li>
app/helpers/matrices_helper.rb:104:in `experiments_progress_bar'
app/views/matrices/_detail.html.erb:13
app/views/matrices/_detail.html.erb:12
app/views/matrices/show.html.erb:12
app/controllers/matrices_controller.rb:28:in `show'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
Rendered rescues/_trace (74.6ms)
Rendered rescues/_request_and_response (0.2ms)
Rendering rescues/layout (internal_server_error)