当前位置:  开发笔记 > 编程语言 > 正文

安装bootstrap gem后,页面中的NoMethodError值欢迎

如何解决《安装bootstrapgem后,页面中的NoMethodError值欢迎》经验,为你挑选了1个好方法。

在我安装了bootstrapgem并rails server再次运行后,我收到此错误:

NoMethodError in Pages#welcome
undefined method `environment' for nil:NilClass
  (in /Users/neilpatel/Desktop/Rails/prospects/app/assets/stylesheets/custom.css.scss)

custom.css.scss

@import "bootstrap";

应用程序/视图/布局/ application.html.erb




    
      Prospects

      <%= stylesheet_link_tag    "application", media: "all", "data-turbolinks-track" => true %>
      <%= javascript_include_tag "application", "data-turbolinks-track" => true %>

      <%= csrf_meta_tags %>
    

    
        <%= link_to "Home", "/" %>
        <%= link_to "About", "/about" %>

     <%= yield %>
    

日志/ development.log

Processing by PagesController#welcome as HTML
  Rendered pages/welcome.html.erb within layouts/application (0.1ms)
Completed 500 Internal Server Error in 15ms

ActionView::Template::Error (undefined method `environment' for nil:NilClass
  (in /Users/neilpatel/Desktop/Rails/prospects/app/assets/stylesheets/custom.css.scss)):
    4:  
    5:    Prospects
    6: 
    7:    <%= stylesheet_link_tag    "application", media: "all", "data-turbolinks-track" => true %>
    8:    <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
    9: 
   10:    <%= csrf_meta_tags %>
  app/views/layouts/application.html.erb:7:in `_app_views_layouts_application_html_erb___3923576615849785590_70354614228980'

的Gemfile

source 'https://rubygems.org'

gem 'rails', '4.0.0.rc1'
gem 'sqlite3'
gem 'sass-rails', '~> 4.0.0.rc1'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.0.1'
gem 'bootstrap-sass', '~> 3.1.1'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

应用程序/资产/ JavaScript的/ application.js中

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require turbolinks
//= require_tree .

更新了gemfile运行包更新

'ran bundle update Bundler could not find compatible versions for gem "railties":
  In Gemfile:
    sass-rails (~> 4.0.2) ruby depends on
      railties (< 5.0, >= 4.0.0) ruby

    rails (= 4.0.0.rc1) ruby depends on
      railties (4.0.0.rc1)

DMKE.. 7

这是sass-rails宝石如何与sprocketsSprockets v2.11.1版本之后浮现的宝石集成的问题(参见此处和此处).

要修复它,请更改Gemfile:

gem 'sass-rails', '~> 4.0.2'

并运行bundle update.

注意:您还应该更新您的Rails版本.最新版本是v4.0.4.为此,请将Gemfile更改为

gem 'rails', '~> 4.0.0'

再次,跑bundle update.



1> DMKE..:

这是sass-rails宝石如何与sprocketsSprockets v2.11.1版本之后浮现的宝石集成的问题(参见此处和此处).

要修复它,请更改Gemfile:

gem 'sass-rails', '~> 4.0.2'

并运行bundle update.

注意:您还应该更新您的Rails版本.最新版本是v4.0.4.为此,请将Gemfile更改为

gem 'rails', '~> 4.0.0'

再次,跑bundle update.

推荐阅读
保佑欣疼你的芯疼
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有