LoginSignup
0
0

More than 1 year has passed since last update.

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

Posted at

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を反映することができる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0