Created
May 9, 2017 08:27
-
-
Save saitoxu/7bb93564d4345ed95f61274e9b792b46 to your computer and use it in GitHub Desktop.
2017-05-09
This file contains 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
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) | |
) | |
} |
This file contains 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
const fb = new FormData() | |
fb.append('name', 'saitoxu') | |
fb.append('email', '[email protected]') |
This file contains 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
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