Я только недавно начал писать свои драгоценные камни. Для одного из них требуется гем gnuplot, например:
module Rocker
require "gnuplot"
# ... module code here ...
end
Это прекрасно работает, пока я не добавлю свой гем в config / environment.rb в одном из моих проектов Rails. Тогда не будет загружено ни одной страницы. Я получаю такие ошибки:
Ошибка типа в матрицах # show
Показываются
приложение / просмотров / матрицы / _detail.html.erb
где строка № 13 поднята:
не может дублировать NilClass
След продолжается, но он довольно бесполезен. Мне ясно, что gnuplot создает какой-то конфликт.
Есть ли эквивалент gem для config / environment.rb? Я понимаю, что вы не должны require "rubygems"
больше в драгоценном камне. Как правильно сделать драгоценные камни доступными для моих пользовательских драгоценных камней?
(И да, я подозреваю, что мог бы просто добавить gnuplot в качестве зависимости в моем приложении Rails, но тогда мой гем не пройдет свои модульные тесты.)
Запрошена полная трассировка. Прежде всего, я использую плагин act_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
Если я закомментирую строку act_as_commentable из class Matrix
, сервер запустится. Но когда я пытаюсь загрузить одно из представлений 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)