Git Product home page Git Product logo

Comments (4)

jeremyevans avatar jeremyevans commented on July 29, 2024

I don't think that forme's Rails support should do something just because Rails form_for does so.

I do agree that the authenticity_token should be added automatically for forms using POST, and I'd like to support that on Sinatra as well using rack-csrf.

Personally, I've always thought that Rails' way of trying to fake HTTP verbs that browsers do not support is stupid. I suppose there are Rails applications that rely on it (though none of my Rails apps do), but as it is not strictly necessary, I don't think the method should be added by default.

The utf8 tag I don't think should be added automatically by default either, as I don't like forcing an encoding on people.

That's not to say that we can't add options that add the method and utf8 tags automatically, I just don't want it to be the default.

Ideally the underlying implementation for this this would be something transformer-like that is applied to all new Form objects at the end of Form#initialize. The tricky thing about it is making sure the transformer has the ability to access the necessary context containing the authenticity token.

from forme.

nirvdrum avatar nirvdrum commented on July 29, 2024

Is there a better approach than using _method? Browsers can only do GET or POST (excluding XMLHttpRequest) and I'm not aware of any other other way to get Rails to handle a PUT or DELETE than the _method param. I don't think it's great practice either, but I'm just trying to play with the hand I've been dealt.

from forme.

jeremyevans avatar jeremyevans commented on July 29, 2024

Personally, since browsers only do GET and POST, I don't use other HTTP verbs for actions that I want a browser to execute. For non-browser based applications, I think other HTTP verbs are fine. Considering that forme is a HTML form library designed for browsers, by design it only uses GET and POST.

I do understand playing the hand you've been dealt, and certainly think it would be generally be useful to have a transformer/callback so that all forms created by forme can be modified in a way that suits the app, instead of having to do the same modifications in each call. This even affects my personal usage of forme, since currently I have to add CSRF tags to all POST forms manually.

from forme.

jeremyevans avatar jeremyevans commented on July 29, 2024

Please give this a shot and let me know if it works for you. I think it should be flexible enough to handle most needs.

from forme.

Related Issues (10)

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.