Commit b5e494f7 by Vijay Gawariya

add employee through xml file and redirect on employee show page and redirect…

add employee through xml file and redirect on employee show page and redirect recipee on show recipee page
parent d2770ae9
......@@ -30,8 +30,18 @@ class Api::V1::EmployeesController < ApplicationController
@filename = params[:file];
@lines = File.read(@filename.path)
doc = Nokogiri.XML(@lines, nil, 'utf-8')
print doc
render json: { name: 'vijay' }
firstName = doc.search('FIRSTNAME').text
lastName = doc.search('LASTNAME').text
email = doc.search('EMAIL').text
phone = doc.search('PHONE').text
dob = doc.search('DOB').text
address = doc.search('ADDRESS').text
employee = Employee.create!(firstName: firstName, lastName: lastName, email: email, phone: phone, dob: dob, address: address)
if(employee)
render json: employee
else
reader json: employee.errors
end
end
private
......
......@@ -56,10 +56,11 @@ class NewEmployee extends React.Component {
body: formData
}).then(response => {
if (response.ok) {
this.props.history.push(`/employees`)
return response.json()
}
throw new Error("Network response was not ok.");
}).catch(error => console.log(error.message));
}).then(response => this.props.history.push(`/employee/${response.id}`))
.catch(error => console.log(error.message));
}
onSubmit(event) {
......
......@@ -86,43 +86,43 @@ class NewRecipe extends React.Component {
})
.then(response => {
if (response.ok) {
this.props.history.push(`/recipes`)
return response.json()
}
throw new Error("Network response was not ok.");
})
}).then(response => this.props.history.push(`/recipe/${response.id}`))
.catch(error => console.log(error.message));
}
submitFile(event) {
event.preventDefault();
const url = "/api/v1/recipes/uploadFile";
const { file } = this.state;
if (file.length == 0)
return;
const body = { file };
console.log(body);
const token = document.querySelector('meta[name="csrf-token"]').content;
const formData = new FormData()
formData.append("file", file)
fetch(url, {
method: "POST",
headers: {
"X-CSRF-Token": token,
},
body: formData
})
.then(response => {
if (response.ok) {
alert("AAAAAAAAAAA")
// return response.json();
console.log(response.json);
}
throw new Error("Network response was not ok.");
})
.catch(error => console.log(error.message));
}
// submitFile(event) {
// event.preventDefault();
// const url = "/api/v1/recipes/uploadFile";
// const { file } = this.state;
// if (file.length == 0)
// return;
// const body = { file };
// console.log(body);
// const token = document.querySelector('meta[name="csrf-token"]').content;
// const formData = new FormData()
// formData.append("file", file)
// fetch(url, {
// method: "POST",
// headers: {
// "X-CSRF-Token": token,
// },
// body: formData
// })
// .then(response => {
// if (response.ok) {
// alert("AAAAAAAAAAA")
// // return response.json();
// console.log(response.json);
// }
// throw new Error("Network response was not ok.");
// })
// .catch(error => console.log(error.message));
// }
render() {
return (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment