LoginSignup
5
5

More than 5 years have passed since last update.

Railsでstylusを使う

Posted at

Gemfileに追記

Gemfileに下記を追記して、bundleインストール。

gem 'stylus'
$ bundle install

$ npm install -g stylus も必要?らしい。

initializerファイル作成

下記のファイルを作成。(ファイル名は任意)その中でstylusをrequlre。

/config/initializers/stylus.rb
require 'stylus'
Stylus.compress = true

/config/initializers以下に置かれたファイルは自動で読み込まれるらしい

stylus作成

試しにstylusファイルを新規作成。適当に背景色を変えてみる

/assets/stylesheets/application.css.styl
body
    background-color #999 #

で、

$ rails s

プレビューでなんかエラー出る

すると、localhost:3000 プレビューで下記のようなエラーがでるようになった

Sprockets::Rails::Helper::AssetFilteredError in 〜〜〜〜

とりあえずの解決法?

下記ファイルのなかにある該当部分をfalseに書き換えると、とりあえずエラーはでなくなり、無事背景色が変わった。

/config/environments/development.rb
  config.assets.raise_runtime_errors = false

参考

Rails4.1プロジェクトにteaspoon入れたらエラー出たので調査した - 一から勉強させてください( ̄ω ̄;)

最後に

間違いorもっといい方法などありましたら指摘いただけるとありがたいです。

5
5
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
5
5