Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
react-rails-rspec
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Aman Sharma
react-rails-rspec
Commits
b0553e06
Commit
b0553e06
authored
Oct 01, 2020
by
Vijay Gawariya
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of 35.155.93.82:amansharma/react-rails-rspec
parents
dd8386ce
e0e4d1c7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
12 deletions
+53
-12
employees_controller.rb
app/controllers/api/v1/employees_controller.rb
+5
-3
recipes_controller.rb
app/controllers/api/v1/recipes_controller.rb
+10
-1
Employee.jsx
app/javascript/components/Employee.jsx
+2
-2
NewRecipe.jsx
app/javascript/components/NewRecipe.jsx
+30
-0
Recipe.jsx
app/javascript/components/Recipe.jsx
+2
-2
routes.rb
config/routes.rb
+4
-4
No files found.
app/controllers/api/v1/employees_controller.rb
View file @
b0553e06
...
...
@@ -27,9 +27,11 @@ class Api::V1::EmployeesController < ApplicationController
end
def
uploadFile
# print{'aaaaaaaaaaaaaaaa'}
# print(params.permit(:file),'aaaaaaaaaaaaaaaaa')
render
json:
{
status:
'sucess'
}
@filename
=
params
[
:file
];
@lines
=
File
.
read
(
@filename
.
path
)
doc
=
Nokogiri
.
XML
(
@lines
,
nil
,
'utf-8'
)
print
doc
render
json:
{
name:
'vijay'
}
end
private
...
...
app/controllers/api/v1/recipes_controller.rb
View file @
b0553e06
...
...
@@ -6,6 +6,7 @@ class Api::V1::RecipesController < ApplicationController
def
create
recipe
=
Recipe
.
create!
(
recipe_params
)
print
recipe_params
if
recipe
render
json:
recipe
else
...
...
@@ -27,7 +28,15 @@ class Api::V1::RecipesController < ApplicationController
end
def
uploadFile
render
json:
{
status:
'sucess'
}
@filename
=
params
[
:file
];
@lines
=
File
.
read
(
@filename
.
path
)
doc
=
Nokogiri
.
XML
(
@lines
,
nil
,
'utf-8'
)
name
=
doc
.
search
(
'NAME'
).
text
ingredients
=
doc
.
search
(
'INGREDIENTS'
).
text
instruction
=
doc
.
search
(
'INSTRUCTION'
).
text
Recipe
.
create!
(
name:
name
,
ingredients:
ingredients
,
instruction:
instruction
)
# Recipe.create!(recipe_params)
render
json:
{
msg:
'OK'
}
end
private
...
...
app/javascript/components/Employee.jsx
View file @
b0553e06
...
...
@@ -18,7 +18,7 @@ class Employee extends React.Component {
}
}
=
this
.
props
;
const
url
=
`/api/v1/show/
${
id
}
`
;
const
url
=
`/api/v1/
employee/
show/
${
id
}
`
;
fetch
(
url
)
.
then
(
response
=>
{
...
...
@@ -115,7 +115,7 @@ class Employee extends React.Component {
params
:
{
id
}
}
}
=
this
.
props
;
const
url
=
`/api/v1/destroy/
${
id
}
`
;
const
url
=
`/api/v1/
employee/
destroy/
${
id
}
`
;
const
token
=
document
.
querySelector
(
'meta[name="csrf-token"]'
).
content
;
fetch
(
url
,
{
...
...
app/javascript/components/NewRecipe.jsx
View file @
b0553e06
...
...
@@ -93,6 +93,36 @@ class NewRecipe extends React.Component {
.
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
();
}
throw
new
Error
(
"Network response was not ok."
);
})
.
catch
(
error
=>
console
.
log
(
error
.
message
));
}
render
()
{
return
(
<
div
className=
"container mt-5"
>
...
...
app/javascript/components/Recipe.jsx
View file @
b0553e06
...
...
@@ -18,7 +18,7 @@ class Recipe extends React.Component {
}
}
=
this
.
props
;
const
url
=
`/api/v1/show/
${
id
}
`
;
const
url
=
`/api/v1/
recipe/
show/
${
id
}
`
;
fetch
(
url
)
.
then
(
response
=>
{
...
...
@@ -103,7 +103,7 @@ class Recipe extends React.Component {
params
:
{
id
}
}
}
=
this
.
props
;
const
url
=
`/api/v1/destroy/
${
id
}
`
;
const
url
=
`/api/v1/
recipe/
destroy/
${
id
}
`
;
const
token
=
document
.
querySelector
(
'meta[name="csrf-token"]'
).
content
;
fetch
(
url
,
{
...
...
config/routes.rb
View file @
b0553e06
...
...
@@ -3,8 +3,8 @@ Rails.application.routes.draw do
namespace
:v1
do
get
'employees/index'
post
'employees/create'
get
'/show/:id'
,
to:
'employees#show'
delete
'/destroy/:id'
,
to:
'employees#destroy'
get
'
employee
/show/:id'
,
to:
'employees#show'
delete
'
employee
/destroy/:id'
,
to:
'employees#destroy'
post
'employees/uploadFile'
end
end
...
...
@@ -12,8 +12,8 @@ Rails.application.routes.draw do
namespace
:v1
do
get
'recipes/index'
post
'recipes/create'
get
'/show/:id'
,
to:
'recipes#show'
delete
'/destroy/:id'
,
to:
'recipes#destroy'
get
'
recipe
/show/:id'
,
to:
'recipes#show'
delete
'
recipe
/destroy/:id'
,
to:
'recipes#destroy'
post
'recipes/uploadFile'
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment