Giter Club home page Giter Club logo

elm-rails's Introduction

Convenience functions for working with Elm in Rails

If you see lots of 401 responses on requests other than GET requests, it's likely because elm-rails doesn't know about the CSRF token Rails includes in the header in a <meta> tag. For a drop-in fix, include csrf-xhr on all pages which use elm-rails. (Alternatively, you can pass the token into your Elm program through a flag, store it in your Model, and add the header to all requests manually. Needless to say, including csrf-xhr on the page is much easier!)

As of Elm 0.19 this package is just maintained so that calls in existing code don't need to change. New projects should use the standard elm/http library and manage the csrf header through one of the methods described above.


NoRedInk

elm-rails's People

Contributors

avh4 avatar bcardiff avatar bowbahdoe avatar brianhicks avatar eeue56 avatar ento avatar joneshf avatar jwoudenberg avatar michaelglass avatar ream88 avatar rtfeldman avatar stoeffel avatar strickinato avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

elm-rails's Issues

Replace Rails.Error with Rails.Result union type?

The Rails.Error type is messy to work with due to all the nesting, and is also frequently wrapping in a Result in any case (see decodeErrors returns Result (Rails.Error e) a).

I think this would be more straightforward to work with if type alias Error were removed and replaced with something like

type Result x a    -- would be fine with better variable names if suggested
    = Ok a
    | AppErr Http.Error x
    | HttpErr Http.Error

Example project?

I'm very new to Elm and wanting to interact with my Rails API. I've been staring at this for days trying to figure out how to make it work but can't seem to put it together by looking at the hats snippets in the documentation. I'm really wishing somebody smarter than myself could put together a very simple example of performing a get and a post for a simple item using this module.

The biggest void in my understanding is how to make a ResponseDecoder.

Referring to the GET sample, it's unclear to me what's going on in the hats function in the documentation.

Send a GET request to the given URL. You also specify how to decode the response.
import Json.Decode (list, string)
hats : String -> Task (Error (List String)) (List String)
hats authToken =
    get (decoder (list string) (succeed ())) "http://example.com/hat-categories.json"

From my limited understanding I see from the Type Annotation that hats takes a String argument and returns a Task (Error (List String)) (List String). Then in the function it takes the string authToken and runs a get request, however I don't see the authToken string ever being used, so why is it being passed in?

Anyway, any help and guidance is greatly appreciated. Thanks!

Update to elm 0.18

Hi there,

I'd love to upgrade my rails-elm project to elm 0.18. Do you have a timeline for upgrading elm-rails to 0.18?

Thanks!

Empty csrf-token

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.