Skip to content

Instantly share code, notes, and snippets.

@saitoxu
Created May 9, 2017
Embed
What would you like to do?
2017-05-09
onSubmit(e) {
e.preventDefault()
const fd = new FormData()
fd.append('user[name]', this.state.name)
fd.append('user[email]', this.state.email)
fetch('http://example.com/users', {
method: 'POST',
body: fd
}).then(response =>
response.json()
).then((json) => {
// do something
}).catch(err =>
console.log(err)
)
}
const fb = new FormData()
fb.append('name', 'saitoxu')
fb.append('email', 'saitoxu@example.com')
class UsersController < ApplicationController
def create
user = User.new(user_params)
if user.save
render json: { status: 'success' }
else
render json: { status: 'failure' }
end
end
private
def user_params
params.require(:user).permit(:name, :email)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment