LoginSignup
3
3

More than 5 years have passed since last update.

PadrinoでCoffeeScriptを使う

Last updated at Posted at 2014-09-26

プラグイン追加

以下のコマンドで既存のプロジェクトにcoffeescriptプラグインを追加。

$ padrino g plugin coffee

Gemfileapp/app.rbに必要なgemや設定が追記され、lib/coffee_initializer.rbが作成される。

gemインストール

Gemfileに追記されたgemをインストール。

$ bundle install

therubyracerがインストールされていない場合は、Gemfileに追記してからbundle install

coffeescript追加

public/javascripts/以下に.coffeeファイルを追加。

public/javascripts/hello.coffee
console.log 'Hello coffee'

viewから呼び出し

通常のjavascript呼び出しと同様に、javascript_include_tagでok。

hoge.slim
= javascript_include_tag 'top'

※ 例ではテンプレートエンジンにslimを使っている

参照

PadrinoでもCoffeeScriptをつかいたい

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