前提・実現したいこと
Ruby、Ruby on rails を某参考書をもとに勉強しているのですが、
cssの表示に以下のエラーが発生しました。
以下のプログラムが正常に読み込まれたらページにアセットが読み込まれ、
Hello,world!というアラートが表示され、OKを押すと
ページにHello,world! という文字が太字で表示されるそうです。
参考書を見たり、ネットで調べてみたのですが、解決せず、ここにて質問させて頂きました。
発生している問題・エラーメッセージ
http://localhost:3000/usersにアクセスすると以下のメッセージが出てきます。
Sprockets::Rails::Helper::AssetNotPrecompiled in Users#index
Showing C:/Users/(ユーザー名)/sample/app/views/users/index.html.erb where line #1 raised:
Asset was not declared to be precompiled in production.
Add Rails.application.config.assets.precompile += %w( users.css )
to config/initializers/assets.rb
and restart your server
Extracted source (around line #1):
<%= stylesheet_link_tag 'users' %> <%= javascript_include_tag 'users' %> <div class='users-index'><%= @hello %></div>
ターミナルの方には以下のようなメッセージが出ています。
ActionView::Template::Error (Asset was not declared to be precompiled in production. Add `Rails.application.config.assets.precompile += %w( users.css )` to `config/initializers/assets.rb` and restart your server): 1: <%= stylesheet_link_tag 'users' %> 2: <%= javascript_include_tag 'users' %> 3: 4: <div class='users-index'><%= @hello %></div>
該当のソースコード
app/views/users/index.html.erb
Ruby
1<%= stylesheet_link_tag 'users' %> 2<%= javascript_include_tag 'users' %> 3 4<div class='users-index'><%= @hello %></div>
app/assets/stylesheets/users.scss
Ruby
1// Place all the styles related to the users controller here. 2// They will automatically be included in application.css. 3// You can use Sass (SCSS) here: http://sass-lang.com/ 4.users-index{ 5 font-weight: bold; 6}
app/assets/javascripts/users.coffee
Ruby
1# Place all the behaviors and hooks related to the matching controller here. 2# All this logic will automatically be available in application.js. 3# You can use CoffeeScript in this file: http://coffeescript.org/ 4alert('Hello, world!')
config/initializers/assets.rb
Ruby
1# Be sure to restart your server when you modify this file. 2 3# Version of your assets, change this if you want to expire all your assets. 4Rails.application.config.assets.version = '1.0' 5 6# Add additional assets to the asset load path. 7# Rails.application.config.assets.paths << Emoji.images_path 8# Add Yarn node_modules folder to the asset load path. 9Rails.application.config.assets.paths << Rails.root.join('node_modules') 10 11# Precompile additional assets. 12# application.js, application.css, and all non-JS/CSS in the app/assets 13# folder are already added. 14# Rails.application.config.assets.precompile += %w( users.js users.css )
試したこと
Add Rails.application.config.assets.precompile += %w( users.css )
to config/initializers/assets.rb
and restart your server
と書いてあるのですが config/initializers/assets.rb
に既に Rails.application.config.assets.precompile += %w( users.css )
と書いてあるのですが…。
Rails.application.config.assets.precompile += %w( users.css )
の下の行にもう一度Rails.application.config.assets.precompile += %w( users.css )
を書いたのですが、同じエラーが出てきてしまいました。
あと、マニフェストファイル
(app/assets/stylesheets/application.cssとapp/assets/javascripts/application.js)から
require_treeの記述を削除しました。
どなたかcssが読み込まれ、表示する方法が分かる方いましたら、よろしくお願いいたします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/06/08 13:41