elm-rails
makes it easy to use Elm modules in your Ruby on Rails applications. This project was heavily inspired by react-rails.
This gem is tested against Ruby 2.2 and 2.3, and Rails versions 4.2.7 and 5.0. It may work on other versions, and if you want to open a PR adding tests against those versions they would be welcome.
-
Add elm-rails to your
Gemfile
and runbundle install
gem "elm-rails"
-
Create a new directory to house all Elm modules
mkdir app/assets/elm
-
Update
.gitignore
to ignore elm files/elm-stuff
-
Define your elm modules in the
app/assets/elm
directory.app/assets/elm/Hello.elm
module Hello exposing (..) import Html exposing (text) port noun : String main = text ("Hello " ++ noun)
-
Open your
app/assets/javascript.js
and require yourHello.elm
.
//= require Hello
-
Use the view helper to insert your component into your view. Pass port values as a
Hash
.<h1>This is an Elm component!</h1> <%= elm_embed('Elm.Hello', { noun: 'World!' }) %>
-
That's it!
There is nothing to configure, but you should have Elm installed in your system
and elm-make
must be availble in your path.