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
Show 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
...
@@ -27,9 +27,11 @@ class Api::V1::EmployeesController < ApplicationController
end
end
def
uploadFile
def
uploadFile
# print{'aaaaaaaaaaaaaaaa'}
@filename
=
params
[
:file
];
# print(params.permit(:file),'aaaaaaaaaaaaaaaaa')
@lines
=
File
.
read
(
@filename
.
path
)
render
json:
{
status:
'sucess'
}
doc
=
Nokogiri
.
XML
(
@lines
,
nil
,
'utf-8'
)
print
doc
render
json:
{
name:
'vijay'
}
end
end
private
private
...
...
app/controllers/api/v1/recipes_controller.rb
View file @
b0553e06
...
@@ -6,6 +6,7 @@ class Api::V1::RecipesController < ApplicationController
...
@@ -6,6 +6,7 @@ class Api::V1::RecipesController < ApplicationController
def
create
def
create
recipe
=
Recipe
.
create!
(
recipe_params
)
recipe
=
Recipe
.
create!
(
recipe_params
)
print
recipe_params
if
recipe
if
recipe
render
json:
recipe
render
json:
recipe
else
else
...
@@ -27,7 +28,15 @@ class Api::V1::RecipesController < ApplicationController
...
@@ -27,7 +28,15 @@ class Api::V1::RecipesController < ApplicationController
end
end
def
uploadFile
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
end
private
private
...
...
app/javascript/components/Employee.jsx
View file @
b0553e06
...
@@ -18,7 +18,7 @@ class Employee extends React.Component {
...
@@ -18,7 +18,7 @@ class Employee extends React.Component {
}
}
}
=
this
.
props
;
}
=
this
.
props
;
const
url
=
`/api/v1/show/
${
id
}
`
;
const
url
=
`/api/v1/
employee/
show/
${
id
}
`
;
fetch
(
url
)
fetch
(
url
)
.
then
(
response
=>
{
.
then
(
response
=>
{
...
@@ -115,7 +115,7 @@ class Employee extends React.Component {
...
@@ -115,7 +115,7 @@ class Employee extends React.Component {
params
:
{
id
}
params
:
{
id
}
}
}
}
=
this
.
props
;
}
=
this
.
props
;
const
url
=
`/api/v1/destroy/
${
id
}
`
;
const
url
=
`/api/v1/
employee/
destroy/
${
id
}
`
;
const
token
=
document
.
querySelector
(
'meta[name="csrf-token"]'
).
content
;
const
token
=
document
.
querySelector
(
'meta[name="csrf-token"]'
).
content
;
fetch
(
url
,
{
fetch
(
url
,
{
...
...
app/javascript/components/NewRecipe.jsx
View file @
b0553e06
...
@@ -93,6 +93,36 @@ class NewRecipe extends React.Component {
...
@@ -93,6 +93,36 @@ class NewRecipe extends React.Component {
.
catch
(
error
=>
console
.
log
(
error
.
message
));
.
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
()
{
render
()
{
return
(
return
(
<
div
className=
"container mt-5"
>
<
div
className=
"container mt-5"
>
...
...
app/javascript/components/Recipe.jsx
View file @
b0553e06
...
@@ -18,7 +18,7 @@ class Recipe extends React.Component {
...
@@ -18,7 +18,7 @@ class Recipe extends React.Component {
}
}
}
=
this
.
props
;
}
=
this
.
props
;
const
url
=
`/api/v1/show/
${
id
}
`
;
const
url
=
`/api/v1/
recipe/
show/
${
id
}
`
;
fetch
(
url
)
fetch
(
url
)
.
then
(
response
=>
{
.
then
(
response
=>
{
...
@@ -103,7 +103,7 @@ class Recipe extends React.Component {
...
@@ -103,7 +103,7 @@ class Recipe extends React.Component {
params
:
{
id
}
params
:
{
id
}
}
}
}
=
this
.
props
;
}
=
this
.
props
;
const
url
=
`/api/v1/destroy/
${
id
}
`
;
const
url
=
`/api/v1/
recipe/
destroy/
${
id
}
`
;
const
token
=
document
.
querySelector
(
'meta[name="csrf-token"]'
).
content
;
const
token
=
document
.
querySelector
(
'meta[name="csrf-token"]'
).
content
;
fetch
(
url
,
{
fetch
(
url
,
{
...
...
config/routes.rb
View file @
b0553e06
...
@@ -3,8 +3,8 @@ Rails.application.routes.draw do
...
@@ -3,8 +3,8 @@ Rails.application.routes.draw do
namespace
:v1
do
namespace
:v1
do
get
'employees/index'
get
'employees/index'
post
'employees/create'
post
'employees/create'
get
'/show/:id'
,
to:
'employees#show'
get
'
employee
/show/:id'
,
to:
'employees#show'
delete
'/destroy/:id'
,
to:
'employees#destroy'
delete
'
employee
/destroy/:id'
,
to:
'employees#destroy'
post
'employees/uploadFile'
post
'employees/uploadFile'
end
end
end
end
...
@@ -12,8 +12,8 @@ Rails.application.routes.draw do
...
@@ -12,8 +12,8 @@ Rails.application.routes.draw do
namespace
:v1
do
namespace
:v1
do
get
'recipes/index'
get
'recipes/index'
post
'recipes/create'
post
'recipes/create'
get
'/show/:id'
,
to:
'recipes#show'
get
'
recipe
/show/:id'
,
to:
'recipes#show'
delete
'/destroy/:id'
,
to:
'recipes#destroy'
delete
'
recipe
/destroy/:id'
,
to:
'recipes#destroy'
post
'recipes/uploadFile'
post
'recipes/uploadFile'
end
end
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