Created
February 20, 2015 17:01
-
-
Save xionon/d0e0ce2535c8724b058b to your computer and use it in GitHub Desktop.
rails jsx helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var RailsForm = React.createClass({ | |
propTypes: { | |
csrf: React.PropTypes.shape({ | |
param: React.PropTypes.string, | |
token: React.PropTypes.string | |
}).isRequired | |
}, | |
getDefaultProps: function() { | |
return { | |
method: "post" | |
} | |
}, | |
render: function() { | |
return ( | |
<form acceptCharset="UTF-8" { ...this.props } method="post" > | |
<input type="hidden" name="_method" value={this.props.method} /> | |
<input type="hidden" name={this.props.csrf.param} value={this.props.csrf.token} /> | |
{this.props.children} | |
</form> | |
); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This class will help you generate forms valid for Rails. You will need to pass your CSRF param & token in as a property, so that Rails can validate the request. If you are using Jbuilder, just add this to the
.json.jbuilder
template that you pass intoreact_component
:You can use the element like so: