Hi there!
Thanks for elm-rails!
I'm having a some trouble with the csrf-tokens.
I followed https://blog.abevoelker.com/2016-09-05/adding-elm-to-a-rails-application using webpack to integrate elm in a rails app and added elm-rails.
I used
Rails.send "PATCH" url body
|> Rails.fromJson (Rails.decoder success failure)
to build the request, but my Rails console complains with: "Can't verify CSRF token authenticity." I checked Rails.csrfToken in my view and it returns Nothing
as well, although in my header I can see <meta name="csrf-token" content="...">
Disabling forgery_protection let's me see the sent data arrive in rails. So I guess everything except the csrf token is okay.
The documentation for csrfToken
wisely pointed out that it only returns a token
If there was a <meta name="csrf-token">
tag in the page's <head>
when elm-rails loaded.
So I guess elm-rails is loaded too early?
I've added <%= javascript_include_tag *webpack_asset_paths("application") %>
"right above the closing tag" as suggested in the blog post above.
I've tried explicitly enclosing Elm...embed
in $( window ).load
to no avail. My next idea was to try around with timeouts in the JS files, but that just seemed wrong.
So I'd be glad to get some help.
How do I find out if the load order is really the problem? If it is: How do I change it? From what I understand webpack runs as its own server, serving the elm code, which might be responsible for timing issues. Do I have to change something about webpack?
I've seen 7c6ba93 which looks like it could solve my problem, but I don't know how to use code that is not packaged yet. Is there something like bundler's source git?
Any other ideas?
Thanks in advance!