未定义的方法`[]' for" image":Sass :: Script :: Value :: String

时间:2017-02-04 08:42:06

标签: ruby-on-rails sprockets

我正在尝试在我的rails应用程序中添加Bootstrap,但我收到此错误:

   NoMethodError undefined method `[]’ for “image”:Sass::Script::Value::String

在以下一行

   <%= stylesheet_link_tag "application", media: "all" %>

这是 application.html fil e,其中发生了此错误:

<!DOCTYPE html>
<html>
  <head>
<title><%= full_title(yield(:title)) %></title>
    <%= csrf_meta_tags %>

    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->  

</head>

  <body>
<header class="navbar navbar-fixed-top">
  <div class="navbar-inner">
     <div class="container">
       <%= link_to "sample app", '#', id: "logo" %>
     <nav>
      <ul class="nav pull-right">
         <li><%= link_to "Home", '#' %></li>
         <li><%= link_to "Help",'#' %></li>
         <li><%= link_to "Sign In",'#' %></li>
     </ul>
     </nav>
     </div>
   </div>
</header>
    <div class="container">
       <%= yield %>
    </div>
  </body>
</html>

home.html 文件中的&#34; image&#34;正在使用的是:

<div class="center hero-unit">
<h1>Welcome to the Sample App</h1>
<h2>
This is the home page for the
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
sample application.
</h2>
<%= link_to "Sign up now!", '#', class: "btn btn-large btn-primary" %>
</div>
<%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %>

以下是错误的完整描述:

sprockets-rails (2.3.3) lib/sprockets/rails/helper.rb:88:in `asset_path'
sprockets (3.4.0) lib/sprockets/sass_processor.rb:124:in `asset_path'
sprockets (3.4.0) lib/sprockets/sass_processor.rb:137:in `asset_url'
sass (3.4.23) lib/sass/script/tree/funcall.rb:143:in `_perform'
sass (3.4.23) lib/sass/script/tree/node.rb:58:in `perform'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:397:in `visit_prop'
sass (3.4.23) lib/sass/tree/visitors/base.rb:36:in `visit'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:160:in `block in visit'
sass (3.4.23) lib/sass/stack.rb:79:in `block in with_base'
sass (3.4.23) lib/sass/stack.rb:115:in `with_frame'
sass (3.4.23) lib/sass/stack.rb:79:in `with_base'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:160:in `visit'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:433:in `block (2 levels) in visit_rule'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:433:in `map'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:433:in `block in visit_rule'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:181:in `with_environment'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:431:in `visit_rule'
sass (3.4.23) lib/sass/tree/visitors/base.rb:36:in `visit'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:160:in `block in visit'
sass (3.4.23) lib/sass/stack.rb:79:in `block in with_base'
sass (3.4.23) lib/sass/stack.rb:115:in `with_frame'
sass (3.4.23) lib/sass/stack.rb:79:in `with_base'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:160:in `visit'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:328:in `block (2 levels) in visit_import'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:328:in `map'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:328:in `block in visit_import'
sass (3.4.23) lib/sass/stack.rb:88:in `block in with_import'
sass (3.4.23) lib/sass/stack.rb:115:in `with_frame'
sass (3.4.23) lib/sass/stack.rb:88:in `with_import'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:325:in `visit_import'
sass (3.4.23) lib/sass/tree/visitors/base.rb:36:in `visit'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:160:in `block in visit'
sass (3.4.23) lib/sass/stack.rb:79:in `block in with_base'
sass (3.4.23) lib/sass/stack.rb:115:in `with_frame'
sass (3.4.23) lib/sass/stack.rb:79:in `with_base'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:160:in `visit'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:328:in `block (2 levels) in visit_import'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:328:in `map'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:328:in `block in visit_import'
sass (3.4.23) lib/sass/stack.rb:88:in `block in with_import'
sass (3.4.23) lib/sass/stack.rb:115:in `with_frame'
sass (3.4.23) lib/sass/stack.rb:88:in `with_import'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:325:in `visit_import'
sass (3.4.23) lib/sass/tree/visitors/base.rb:36:in `visit'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:160:in `block in visit'
sass (3.4.23) lib/sass/stack.rb:79:in `block in with_base'
sass (3.4.23) lib/sass/stack.rb:115:in `with_frame'
sass (3.4.23) lib/sass/stack.rb:79:in `with_base'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:160:in `visit'
sass (3.4.23) lib/sass/tree/visitors/base.rb:52:in `block in visit_children'
sass (3.4.23) lib/sass/tree/visitors/base.rb:52:in `map'
sass (3.4.23) lib/sass/tree/visitors/base.rb:52:in `visit_children'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:169:in `block in visit_children'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:181:in `with_environment'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:168:in `visit_children'
sass (3.4.23) lib/sass/tree/visitors/base.rb:36:in `block in visit'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:188:in `visit_root'
sass (3.4.23) lib/sass/tree/visitors/base.rb:36:in `visit'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:159:in `visit'
sass (3.4.23) lib/sass/tree/visitors/perform.rb:8:in `visit'
sass (3.4.23) lib/sass/tree/root_node.rb:36:in `css_tree'
sass (3.4.23) lib/sass/tree/root_node.rb:20:in `render'
sass (3.4.23) lib/sass/engine.rb:281:in `render'
sass-rails (5.0.6) lib/sass/rails/template.rb:47:in `evaluate'
tilt (2.0.5) lib/tilt/template.rb:102:in `render'
sprockets (3.4.0) lib/sprockets/legacy_tilt_processor.rb:25:in `call'
sprockets (3.4.0) lib/sprockets/processor_utils.rb:75:in `call_processor'
sprockets (3.4.0) lib/sprockets/processor_utils.rb:57:in `block in call_processors'
sprockets (3.4.0) lib/sprockets/processor_utils.rb:56:in `reverse_each'
sprockets (3.4.0) lib/sprockets/processor_utils.rb:56:in `call_processors'
sprockets (3.4.0) lib/sprockets/loader.rb:134:in `load_from_unloaded'
sprockets (3.4.0) lib/sprockets/loader.rb:60:in `block in load'
sprockets (3.4.0) lib/sprockets/loader.rb:318:in `fetch_asset_from_dependency_cache'
sprockets (3.4.0) lib/sprockets/loader.rb:44:in `load'
sprockets (3.4.0) lib/sprockets/cached_environment.rb:20:in `block in initialize'
sprockets (3.4.0) lib/sprockets/cached_environment.rb:47:in `yield'
sprockets (3.4.0) lib/sprockets/cached_environment.rb:47:in `load'
sprockets (3.4.0) lib/sprockets/bundle.rb:23:in `block in call'
sprockets (3.4.0) lib/sprockets/utils.rb:183:in `dfs'
sprockets (3.4.0) lib/sprockets/bundle.rb:24:in `call'
sprockets (3.4.0) lib/sprockets/processor_utils.rb:75:in `call_processor'
sprockets (3.4.0) lib/sprockets/processor_utils.rb:57:in `block in call_processors'
sprockets (3.4.0) lib/sprockets/processor_utils.rb:56:in `reverse_each'
sprockets (3.4.0) lib/sprockets/processor_utils.rb:56:in `call_processors'
sprockets (3.4.0) lib/sprockets/loader.rb:134:in `load_from_unloaded'
sprockets (3.4.0) lib/sprockets/loader.rb:60:in `block in load'
sprockets (3.4.0) lib/sprockets/loader.rb:318:in `fetch_asset_from_dependency_cache'
sprockets (3.4.0) lib/sprockets/loader.rb:44:in `load'
sprockets (3.4.0) lib/sprockets/cached_environment.rb:20:in `block in initialize'
sprockets (3.4.0) lib/sprockets/cached_environment.rb:47:in `yield'
sprockets (3.4.0) lib/sprockets/cached_environment.rb:47:in `load'
sprockets (3.4.0) lib/sprockets/base.rb:66:in `find_asset'
sprockets (3.4.0) lib/sprockets/environment.rb:30:in `find_asset'
sprockets (3.4.0) lib/sprockets/base.rb:92:in `[]'
sprockets-rails (2.3.3) lib/sprockets/rails/helper.rb:230:in `lookup_asset_for_path'
sprockets-rails (2.3.3) lib/sprockets/rails/helper.rb:160:in `block in stylesheet_link_tag'
sprockets-rails (2.3.3) lib/sprockets/rails/helper.rb:158:in `map'
sprockets-rails (2.3.3) lib/sprockets/rails/helper.rb:158:in `stylesheet_link_tag'
app/views/layouts/application.html.erb:7:in `_app_views_layouts_application_html_erb__3811303766606918321_69911174356720'
actionview (5.0.1) lib/action_view/template.rb:159:in `block in render'
activesupport (5.0.1) lib/active_support/notifications.rb:166:in `instrument'
actionview (5.0.1) lib/action_view/template.rb:354:in `instrument'
actionview (5.0.1) lib/action_view/template.rb:157:in `render'
actionview (5.0.1) lib/action_view/renderer/template_renderer.rb:66:in `render_with_layout'
actionview (5.0.1) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
actionview (5.0.1) lib/action_view/renderer/template_renderer.rb:14:in `render'
actionview (5.0.1) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionview (5.0.1) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (5.0.1) lib/action_view/rendering.rb:103:in `_render_template'
actionpack (5.0.1) lib/action_controller/metal/streaming.rb:217:in `_render_template'
actionview (5.0.1) lib/action_view/rendering.rb:83:in `render_to_body'
actionpack (5.0.1) lib/action_controller/metal/rendering.rb:52:in `render_to_body'
actionpack (5.0.1) lib/action_controller/metal/renderers.rb:142:in `render_to_body'
actionpack (5.0.1) lib/abstract_controller/rendering.rb:26:in `render'
actionpack (5.0.1) lib/action_controller/metal/rendering.rb:36:in `render'
actionpack (5.0.1) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
activesupport (5.0.1) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/usr/local/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
activesupport (5.0.1) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (5.0.1) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
actionpack (5.0.1) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
activerecord (5.0.1) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (5.0.1) lib/action_controller/metal/instrumentation.rb:43:in `render'
actionpack (5.0.1) lib/action_controller/metal/implicit_render.rb:36:in `default_render'
actionpack (5.0.1) lib/action_controller/metal/basic_implicit_render.rb:4:in `block in send_action'
actionpack (5.0.1) lib/action_controller/metal/basic_implicit_render.rb:4:in `tap'
actionpack (5.0.1) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.0.1) lib/abstract_controller/base.rb:188:in `process_action'
actionpack (5.0.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.0.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (5.0.1) lib/active_support/callbacks.rb:126:in `call'
activesupport (5.0.1) lib/active_support/callbacks.rb:126:in `call'
activesupport (5.0.1) lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
activesupport (5.0.1) lib/active_support/callbacks.rb:455:in `call'
activesupport (5.0.1) lib/active_support/callbacks.rb:455:in `call'
activesupport (5.0.1) lib/active_support/callbacks.rb:101:in `__run_callbacks__'
activesupport (5.0.1) lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
activesupport (5.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.1) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.0.1) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.0.1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (5.0.1) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (5.0.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.0.1) lib/active_support/notifications.rb:164:in `instrument'
actionpack (5.0.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.0.1) lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
activerecord (5.0.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (5.0.1) lib/abstract_controller/base.rb:126:in `process'
actionview (5.0.1) lib/action_view/rendering.rb:30:in `process'
actionpack (5.0.1) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (5.0.1) lib/action_controller/metal.rb:262:in `dispatch'
actionpack (5.0.1) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (5.0.1) lib/action_dispatch/routing/route_set.rb:32:in `serve'
actionpack (5.0.1) lib/action_dispatch/journey/router.rb:39:in `block in serve'
actionpack (5.0.1) lib/action_dispatch/journey/router.rb:26:in `each'
actionpack (5.0.1) lib/action_dispatch/journey/router.rb:26:in `serve'
actionpack (5.0.1) lib/action_dispatch/routing/route_set.rb:725:in `call'
rack (2.0.1) lib/rack/etag.rb:25:in `call'
rack (2.0.1) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.1) lib/rack/head.rb:12:in `call'
rack (2.0.1) lib/rack/session/abstract/id.rb:222:in `context'
rack (2.0.1) lib/rack/session/abstract/id.rb:216:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.0.1) lib/active_record/migration.rb:553:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
activesupport (5.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
activesupport (5.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.1) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
web-console (3.4.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.4.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.4.0) lib/web_console/middleware.rb:18:in `catch'
web-console (3.4.0) lib/web_console/middleware.rb:18:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.1) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.1) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.1) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.0.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.1) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.0.1) lib/rails/rack/logger.rb:24:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.0.1) lib/rack/method_override.rb:22:in `call'
rack (2.0.1) lib/rack/runtime.rb:22:in `call'
activesupport (5.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
railties (5.0.1) lib/rails/engine.rb:522:in `call'
puma (3.6.2) lib/puma/configuration.rb:225:in `call'
puma (3.6.2) lib/puma/server.rb:578:in `handle_request'
puma (3.6.2) lib/puma/server.rb:415:in `process_client'
puma (3.6.2) lib/puma/server.rb:275:in `block in run'
puma (3.6.2) lib/puma/thread_pool.rb:116:in `call'
puma (3.6.2) lib/puma/thread_pool.rb:116:in `block in spawn_thread'

我还试过从3.7到3.4降级链轮和链轮导轨到2.3.2。正如建议here但问题尚未解决。  我使用rails 5ruby 2.2.2 我是rails的新手,无法理解这个错误。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:3)

我认为你的问题与我的问题相同。我想这可能是你的问题。当我的应用程序从3.2升级到4.2时,这解决了我:

http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#sass-rails

错误原因:

  不推荐使用带有两个参数的

asset-url。例如:asset-url(“rails.png”,image)变为asset-url(“rails.png”)。

答案 1 :(得分:0)

我有同样的错误。这是样式表扩展名中的问题。它通过app / assets / stylesheets / application.css和其他文件app / assets / stylesheets / yourfile.css.scss重命名扩展名而得到解决,我在应用程序中使用了代码@import Bootstrap .css这对我有用。