LoginSignup
2
0

More than 5 years have passed since last update.

Elm&Rails5.1の環境構築 (globalに干渉せずに)

Last updated at Posted at 2017-11-18

Rails5.1のwebpackerを用いて、Elmの環境を構築したのでメモ。

Rails5.1の導入

https://qiita.com/emadurandal/items/e43c4896be1df60caef0
にRailsをローカルにインストールする丁寧な解説が載っているので、これをそのまま実行しました。
(記事では、5.xは未確認となっていますが、問題なかったです)
Gemfileのrailsのバージョンを指定しなければ、最新がインストールされます。

Webpackerの導入

$ bundle exec rails server

でrailsサーバーが立ち上がったら、Webpackerをダウンロードします。

Gemfileに

gem 'webpacker'

を追加して、

$ bundle install --path vendor/bundle

を実行。

Elmのインストール

$ bundle exec rails webpacker:instal:elm

でElmがインストールされます。

確認方法としては、Main.elmが自動で生成されているので、これを表示してみる。

# app/view/application/index.html.erb

<%= javascript_pack_tag "hello_elm" %>

# config/routes.rb

Rails.application.routes.draw do
  get '/', to: 'application#index'
end

これらを書き足したら、をもう一回サーバーを立ち上げると「Hello Elm!」とブラウザに表示されるはずです。

$ bundle exec rails server

経緯

最初に紹介した記事の

$ bundle exec rails new example --skip-bundle

--webpack=elmを付け足して実行してもエラーになったので、対処法を探した次第です。

参考

2
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
2
0