helen's blog

ずっとおもしろいことしてたいな。

railsのどこに外部ライブラリを置くのか1週間くらい悩んだ話

rails newしてプロジェクトがいい感じにできてあがってくれるのは嬉しいけど
それはそれで外部のライブラリの配置に困ったという話

困った時の公式

2.2 Asset Organization
Pipeline assets can be placed inside an application in one of three locations: app/assets, lib/assets or vendor/assets.

app/assets is for assets that are owned by the application, such as custom images, JavaScript files or stylesheets.

lib/assets is for your own libraries' code that doesn't really fit into the scope of the application or those libraries which are shared across applications.

vendor/assets is for assets that are owned by outside entities, such as code for JavaScript plugins and CSS frameworks. Keep in mind that third party code with references to other files also processed by the asset Pipeline (images, stylesheets, etc.), will need to be rewritten to use helpers like asset_path.

The Asset Pipeline — Ruby on Rails Guides

つまり

app/assets

カスタム画像、JS、CSSなど、アプリケーション自身が保有するアセット

lib/assets

1つのアプリケーションのに収まらないライブラリやアプリケーションで共有されるライブラリ

vendor/assets

外部に提供されているJSのプラグインCSSフレームワークなどのアセット
アセットパイプラインに管理してほしければヘルパーに書かなければならない

だそうです

つまりなんらかのJSやCSSフレームワークを使いたければ
vendor/assetsにおいてヘルパーに書くのが一般らしい
railsのバージョンにも気をつけてねと公式に書いてあるのでそこだけ注意

vender/assets配下にjsとcss分けるようなディレクトリがあるけど
ばらすのがめんどう&1つのライブラリをばらすのは気持ちが悪い
というわけでそのままvender/assetsに配置

もっと早くこれ読んでればよかった