Quantcast
Channel: CSSタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8945

railsでcssが反映されないエラーActionController::RoutingError (No route matches [GET] "/stylesheets"):style

$
0
0
app/assets/stylesheets/home.scss 上記のようにhome.scssファイルを作ってcssを書き app/assets/views/home/index.html.erb 上記のようにhomeフォルダにindex.html.erbファイルを作ってhtmlを書いた。 「rails s」でサーバーを起動すると ActionController::RoutingError (No route matches [GET] "/stylesheets") のエラーが起きてしまった。 routes.rb Rails.application.routes.draw do # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html get "index" =>"home#index" get "myactive" => "home#myactive" get "myhobby" => "home#myhobby" get "myskill" => "home#myskill" end ルーティングを確認したが特に問題はなさそう。 home.controller.rb class HomeController < ActionController::Base def index end def myactive end def myhobby end def myskill end end 上の「ActionController::Base」を「ApplicationController」に変更すると上手くいった。 これで理解したこと ・home.controller.rbとはviews/homeフォルダをコントロールするもので  routes.rbでは「home#index」のようにする。home.scssに書く。  home.controller.rbなど新しくファイルを作った場合は、親クラスをApplicationControllerにする。 ・わざわざhome.controller.rbなど新しくファイルを作らなくても、views/applicationフォルダを作り、  既存のapplication.cssにコードを書くとcssを反映することができる。

Viewing all articles
Browse latest Browse all 8945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>