gpt4 book ai didi

jquery - Rails 3 - 未定义方法 `[]' 为 nil :NilClass in application. html.erb

转载 作者:数据小太阳 更新时间:2023-10-29 08:13:59 26 4
gpt4 key购买 nike

我的 Rails 3 应用程序还有另一个问题。我在 Apache 2.4.7 和 Phusion_Passenger 4.0.37 上运行 Ruby 1.9.3p484 和 Rails 3.2.16。

我添加了 jquery-datatables-rails gem 并在添加 *= require dataTables/jquery.dataTables 到我的 application.css 之后我开始有问题了。我收到的错误消息是:

undefined method `[]' for nil:NilClass
Showing /var/www-ruby/SteamBundleHelper/app/views/layouts/application.html.erb where line #5 raised:

我的 application.html.erb 文件的顶部(第 5 行是 stylesheet_link_tag 之一):

<!DOCTYPE html>
<html>
<head>
<title>Steam Bundle Helper</title>
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>

我的 gem 文件:

source 'https://rubygems.org'

gem 'rails', '3.2.16'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby

gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'
gem 'jquery-datatables-rails', '~> 3.3.0'

gem 'minitest'

gem 'nokogiri'

gem 'pry-rails', :group => :development
gem 'pry-debugger', :group => :development
gem 'pry-remote', :group => :development

Gemfile.lock:

GEM
remote: https://rubygems.org/
specs:
actionmailer (3.2.16)
actionpack (= 3.2.16)
mail (~> 2.5.4)
actionpack (3.2.16)
activemodel (= 3.2.16)
activesupport (= 3.2.16)
builder (>= 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.4)
rack (>= 1.4.5)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (>= 2.2)
activemodel (3.2.16)
activesupport (= 3.2.16)
builder (>= 3.0.0)
activerecord (3.2.16)
activemodel (= 3.2.16)
activesupport (= 3.2.16)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.16)
activemodel (= 3.2.16)
activesupport (= 3.2.16)
activesupport (3.2.16)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
arel (3.0.3)
builder (3.2.2)
coderay (1.1.1)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.10.0)
columnize (0.9.0)
concurrent-ruby (1.0.1)
debugger (1.6.8)
columnize (>= 0.3.1)
debugger-linecache (~> 1.2.0)
debugger-ruby_core_source (~> 1.3.5)
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.3.8)
erubis (2.7.0)
execjs (2.6.0)
i18n (0.7.0)
journey (1.0.4)
jquery-datatables-rails (3.3.0)
actionpack (>= 3.1)
jquery-rails
railties (>= 3.1)
sass-rails
jquery-rails (3.1.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.3)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.8.2)
mime-types (1.25.1)
mini_portile2 (2.0.0)
minitest (5.8.4)
multi_json (1.11.2)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
polyglot (0.3.5)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-debugger (0.2.3)
debugger (~> 1.3)
pry (>= 0.9.10, < 0.11.0)
pry-rails (0.3.4)
pry (>= 0.9.10)
pry-remote (0.1.8)
pry (~> 0.9)
slop (~> 3.0)
rack (1.6.4)
rack-cache (1.6.1)
rack (>= 0.4)
rack-ssl (1.3.4)
rack
rack-test (0.6.3)
rack (>= 1.0)
rails (3.2.16)
actionmailer (= 3.2.16)
actionpack (= 3.2.16)
activerecord (= 3.2.16)
activeresource (= 3.2.16)
activesupport (= 3.2.16)
bundler (~> 1.0)
railties (= 3.2.16)
railties (3.2.16)
actionpack (= 3.2.16)
activesupport (= 3.2.16)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (10.5.0)
rdoc (3.12.2)
json (~> 1.4)
sass (3.4.21)
sass-rails (3.2.6)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
slop (3.6.0)
sprockets (3.5.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sqlite3 (1.3.11)
thor (0.19.1)
tilt (1.4.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.46)
uglifier (2.7.2)
execjs (>= 0.3.0)
json (>= 1.8.0)

PLATFORMS
ruby

DEPENDENCIES
coffee-rails (~> 3.2.1)
jquery-datatables-rails (~> 3.3.0)
jquery-rails
minitest
nokogiri
pry-debugger
pry-rails
pry-remote
rails (= 3.2.16)
sass-rails (~> 3.2.3)
sqlite3
uglifier (>= 1.0.3)

我的 application.css 文件:

/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require dataTables/jquery.dataTables
*/

body {
font-size: 14px;
font-family: Verdana, Tahoma, sans-serif;
}

.main_container {
width: 1200px;
margin: 0 auto;
}

.header {
padding-bottom: 3em;
}

.profile_details {
float: right;

}

只要我从 application.css 中删除 *= require dataTables/jquery.dataTables,错误就会消失。问题是我需要 Datatables CSS 文件。我摆弄了很多东西但最终恢复了它们,因为它们没有解决我的问题。欢迎任何想法。

编辑:由于我对 sprocketssass 都不太熟悉,删除链轮的最佳方法是什么,哪个似乎是罪魁祸首,直接编译所有.scss文件?我应该将它们全部@importapplication.css吗?

编辑 #2 (2016-03-29):根据评论中的要求,我附加了(很长的)完整跟踪:

sass-rails (3.2.6) lib/sass/rails/template_handlers.rb:81:in `sass_options'
sass-rails (3.2.6) lib/sass/rails/template_handlers.rb:106:in `evaluate'
/usr/lib/ruby/vendor_ruby/tilt/template.rb:103:in `render'
sprockets (3.5.2) lib/sprockets/legacy_tilt_processor.rb:25:in `call'
sprockets (3.5.2) lib/sprockets/processor_utils.rb:75:in `call_processor'
sprockets (3.5.2) lib/sprockets/processor_utils.rb:57:in `block in call_processors'
sprockets (3.5.2) lib/sprockets/processor_utils.rb:56:in `reverse_each'
sprockets (3.5.2) lib/sprockets/processor_utils.rb:56:in `call_processors'
sprockets (3.5.2) lib/sprockets/loader.rb:134:in `load_from_unloaded'
sprockets (3.5.2) lib/sprockets/loader.rb:60:in `block in load'
sprockets (3.5.2) lib/sprockets/loader.rb:318:in `fetch_asset_from_dependency_cache'
sprockets (3.5.2) lib/sprockets/loader.rb:44:in `load'
sprockets (3.5.2) lib/sprockets/cached_environment.rb:20:in `block in initialize'
sprockets (3.5.2) lib/sprockets/cached_environment.rb:47:in `yield'
sprockets (3.5.2) lib/sprockets/cached_environment.rb:47:in `default'
sprockets (3.5.2) lib/sprockets/cached_environment.rb:47:in `load'
sprockets (3.5.2) lib/sprockets/bundle.rb:23:in `block in call'
sprockets (3.5.2) lib/sprockets/utils.rb:183:in `dfs'
sprockets (3.5.2) lib/sprockets/bundle.rb:24:in `call'
sprockets (3.5.2) lib/sprockets/processor_utils.rb:75:in `call_processor'
sprockets (3.5.2) lib/sprockets/processor_utils.rb:57:in `block in call_processors'
sprockets (3.5.2) lib/sprockets/processor_utils.rb:56:in `reverse_each'
sprockets (3.5.2) lib/sprockets/processor_utils.rb:56:in `call_processors'
sprockets (3.5.2) lib/sprockets/loader.rb:134:in `load_from_unloaded'
sprockets (3.5.2) lib/sprockets/loader.rb:60:in `block in load'
sprockets (3.5.2) lib/sprockets/loader.rb:318:in `fetch_asset_from_dependency_cache'
sprockets (3.5.2) lib/sprockets/loader.rb:44:in `load'
sprockets (3.5.2) lib/sprockets/cached_environment.rb:20:in `block in initialize'
sprockets (3.5.2) lib/sprockets/cached_environment.rb:47:in `yield'
sprockets (3.5.2) lib/sprockets/cached_environment.rb:47:in `default'
sprockets (3.5.2) lib/sprockets/cached_environment.rb:47:in `load'
sprockets (3.5.2) lib/sprockets/base.rb:66:in `find_asset'
sprockets (3.5.2) lib/sprockets/environment.rb:30:in `find_asset'
sprockets (3.5.2) lib/sprockets/base.rb:92:in `[]'
/usr/lib/ruby/vendor_ruby/sprockets/helpers/rails_helper.rb:126:in `asset_for'
/usr/lib/ruby/vendor_ruby/sprockets/helpers/rails_helper.rb:44:in `block in stylesheet_link_tag'
/usr/lib/ruby/vendor_ruby/sprockets/helpers/rails_helper.rb:43:in `collect'
/usr/lib/ruby/vendor_ruby/sprockets/helpers/rails_helper.rb:43:in `stylesheet_link_tag'
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb___3648343695788242355_69996357879600'
/usr/lib/ruby/vendor_ruby/action_view/template.rb:145:in `block in render'
/usr/lib/ruby/vendor_ruby/active_support/notifications.rb:125:in `instrument'
/usr/lib/ruby/vendor_ruby/action_view/template.rb:143:in `render'
/usr/lib/ruby/vendor_ruby/action_view/renderer/template_renderer.rb:59:in `render_with_layout'
/usr/lib/ruby/vendor_ruby/action_view/renderer/template_renderer.rb:45:in `render_template'
/usr/lib/ruby/vendor_ruby/action_view/renderer/template_renderer.rb:18:in `render'
/usr/lib/ruby/vendor_ruby/action_view/renderer/renderer.rb:36:in `render_template'
/usr/lib/ruby/vendor_ruby/action_view/renderer/renderer.rb:17:in `render'
/usr/lib/ruby/vendor_ruby/abstract_controller/rendering.rb:110:in `_render_template'
/usr/lib/ruby/vendor_ruby/action_controller/metal/streaming.rb:225:in `_render_template'
/usr/lib/ruby/vendor_ruby/abstract_controller/rendering.rb:103:in `render_to_body'
/usr/lib/ruby/vendor_ruby/action_controller/metal/renderers.rb:28:in `render_to_body'
/usr/lib/ruby/vendor_ruby/action_controller/metal/compatibility.rb:50:in `render_to_body'
/usr/lib/ruby/vendor_ruby/abstract_controller/rendering.rb:88:in `render'
/usr/lib/ruby/vendor_ruby/action_controller/metal/rendering.rb:16:in `render'
/usr/lib/ruby/vendor_ruby/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
/usr/lib/ruby/vendor_ruby/active_support/core_ext/benchmark.rb:5:in `block in ms'
/usr/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
/usr/lib/ruby/vendor_ruby/active_support/core_ext/benchmark.rb:5:in `ms'
/usr/lib/ruby/vendor_ruby/action_controller/metal/instrumentation.rb:40:in `block in render'
/usr/lib/ruby/vendor_ruby/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
/usr/lib/ruby/vendor_ruby/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
/usr/lib/ruby/vendor_ruby/action_controller/metal/instrumentation.rb:39:in `render'
/usr/lib/ruby/vendor_ruby/action_controller/metal/implicit_render.rb:10:in `default_render'
/usr/lib/ruby/vendor_ruby/action_controller/metal/implicit_render.rb:5:in `send_action'
/usr/lib/ruby/vendor_ruby/abstract_controller/base.rb:167:in `process_action'
/usr/lib/ruby/vendor_ruby/action_controller/metal/rendering.rb:10:in `process_action'
/usr/lib/ruby/vendor_ruby/abstract_controller/callbacks.rb:18:in `block in process_action'
/usr/lib/ruby/vendor_ruby/active_support/callbacks.rb:414:in `_run__3287941951740287054__process_action__2444081902642250416__callbacks'
/usr/lib/ruby/vendor_ruby/active_support/callbacks.rb:405:in `__run_callback'
/usr/lib/ruby/vendor_ruby/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
/usr/lib/ruby/vendor_ruby/active_support/callbacks.rb:81:in `run_callbacks'
/usr/lib/ruby/vendor_ruby/abstract_controller/callbacks.rb:17:in `process_action'
/usr/lib/ruby/vendor_ruby/action_controller/metal/rescue.rb:29:in `process_action'
/usr/lib/ruby/vendor_ruby/action_controller/metal/instrumentation.rb:30:in `block in process_action'
/usr/lib/ruby/vendor_ruby/active_support/notifications.rb:123:in `block in instrument'
/usr/lib/ruby/vendor_ruby/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/lib/ruby/vendor_ruby/active_support/notifications.rb:123:in `instrument'
/usr/lib/ruby/vendor_ruby/action_controller/metal/instrumentation.rb:29:in `process_action'
/usr/lib/ruby/vendor_ruby/action_controller/metal/params_wrapper.rb:207:in `process_action'
/usr/lib/ruby/vendor_ruby/active_record/railties/controller_runtime.rb:18:in `process_action'
/usr/lib/ruby/vendor_ruby/abstract_controller/base.rb:121:in `process'
/usr/lib/ruby/vendor_ruby/abstract_controller/rendering.rb:45:in `process'
/usr/lib/ruby/vendor_ruby/action_controller/metal.rb:203:in `dispatch'
/usr/lib/ruby/vendor_ruby/action_controller/metal/rack_delegation.rb:14:in `dispatch'
/usr/lib/ruby/vendor_ruby/action_controller/metal.rb:246:in `block in action'
/usr/lib/ruby/vendor_ruby/action_dispatch/routing/route_set.rb:73:in `call'
/usr/lib/ruby/vendor_ruby/action_dispatch/routing/route_set.rb:73:in `dispatch'
/usr/lib/ruby/vendor_ruby/action_dispatch/routing/route_set.rb:36:in `call'
/usr/lib/ruby/vendor_ruby/journey/router.rb:68:in `block in call'
/usr/lib/ruby/vendor_ruby/journey/router.rb:56:in `each'
/usr/lib/ruby/vendor_ruby/journey/router.rb:56:in `call'
/usr/lib/ruby/vendor_ruby/action_dispatch/routing/route_set.rb:608:in `call'
/usr/lib/ruby/vendor_ruby/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
/usr/lib/ruby/vendor_ruby/action_dispatch/middleware/head.rb:14:in `call'
/usr/lib/ruby/vendor_ruby/action_dispatch/middleware/params_parser.rb:21:in `call'
/usr/lib/ruby/vendor_ruby/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
/usr/lib/ruby/vendor_ruby/action_dispatch/middleware/cookies.rb:341:in `call'
/usr/lib/ruby/vendor_ruby/active_record/query_cache.rb:64:in `call'
/usr/lib/ruby/vendor_ruby/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
/usr/lib/ruby/vendor_ruby/action_dispatch/middleware/callbacks.rb:28:in `block in call'
/usr/lib/ruby/vendor_ruby/active_support/callbacks.rb:405:in `_run__411984161693097463__call__4601814333716727330__callbacks'
/usr/lib/ruby/vendor_ruby/active_support/callbacks.rb:405:in `__run_callback'
/usr/lib/ruby/vendor_ruby/active_support/callbacks.rb:385:in `_run_call_callbacks'
/usr/lib/ruby/vendor_ruby/active_support/callbacks.rb:81:in `run_callbacks'
/usr/lib/ruby/vendor_ruby/action_dispatch/middleware/callbacks.rb:27:in `call'
/usr/lib/ruby/vendor_ruby/action_dispatch/middleware/reloader.rb:65:in `call'
/usr/lib/ruby/vendor_ruby/action_dispatch/middleware/remote_ip.rb:31:in `call'
/usr/lib/ruby/vendor_ruby/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
/usr/lib/ruby/vendor_ruby/action_dispatch/middleware/show_exceptions.rb:56:in `call'
/usr/lib/ruby/vendor_ruby/rails/rack/logger.rb:32:in `call_app'
/usr/lib/ruby/vendor_ruby/rails/rack/logger.rb:16:in `block in call'
/usr/lib/ruby/vendor_ruby/active_support/tagged_logging.rb:22:in `tagged'
/usr/lib/ruby/vendor_ruby/rails/rack/logger.rb:16:in `call'
/usr/lib/ruby/vendor_ruby/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
/usr/lib/ruby/vendor_ruby/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
/usr/lib/ruby/vendor_ruby/action_dispatch/middleware/static.rb:63:in `call'
/usr/lib/ruby/vendor_ruby/rails/engine.rb:484:in `call'
/usr/lib/ruby/vendor_ruby/rails/application.rb:231:in `call'
/usr/lib/ruby/vendor_ruby/rails/railtie/configurable.rb:30:in `method_missing'
/usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:77:in `process_request'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:142:in `accept_and_process_next_request'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:110:in `main_loop'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:448:in `block (3 levels) in start_threads'

编辑 #3 (2016-03-30):

如果我从 application.css 中删除所有 require 行,我不会收到任何错误。所以错误来自any require 指令。

最佳答案

看起来您没有加载 Assets 管道,特别是样式表和 javascript。安装 gem 后,从命令行运行 rails generate jquery:datatables:install。您的 application.js 和 application.css 文件应如下所示:

应用程序.js

...
//= require jquery
//= require jquery_ujs
//= require dataTables/jquery.dataTables
//= require turbolinks
//= require_tree .

应用程序.css

...
*= require_tree .
*= require dataTables/jquery.dataTables
*= require_self
*/

关于jquery - Rails 3 - 未定义方法 `[]' 为 nil :NilClass in application. html.erb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35780939/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com