File tree Expand file tree Collapse file tree 8 files changed +95
-24
lines changed Expand file tree Collapse file tree 8 files changed +95
-24
lines changed Original file line number Diff line number Diff line change @@ -14,14 +14,16 @@ gem 'puma', '~> 3.11'
14
14
# Use Redis adapter to run Action Cable in production
15
15
# gem 'redis', '~> 4.0'
16
16
# Use ActiveModel has_secure_password
17
- # gem 'bcrypt', '~> 3.1.7'
17
+ gem 'bcrypt' , '~> 3.1.7'
18
18
19
19
# Use ActiveStorage variant
20
20
# gem 'mini_magick', '~> 4.8'
21
21
22
22
# Use Capistrano for deployment
23
23
# gem 'capistrano-rails', group: :development
24
24
25
+ gem 'active_model_serializers'
26
+
25
27
# Reduces boot times through caching; required in config/boot.rb
26
28
gem 'bootsnap' , '>= 1.1.0' , require : false
27
29
Original file line number Diff line number Diff line change 24
24
erubi (~> 1.4 )
25
25
rails-dom-testing (~> 2.0 )
26
26
rails-html-sanitizer (~> 1.0 , >= 1.0.3 )
27
+ active_model_serializers (0.10.8 )
28
+ actionpack (>= 4.1 , < 6 )
29
+ activemodel (>= 4.1 , < 6 )
30
+ case_transform (>= 0.2 )
31
+ jsonapi-renderer (>= 0.1.1.beta1 , < 0.3 )
27
32
activejob (5.2.1 )
28
33
activesupport (= 5.2.1 )
29
34
globalid (>= 0.3.6 )
43
48
minitest (~> 5.1 )
44
49
tzinfo (~> 1.1 )
45
50
arel (9.0.0 )
51
+ bcrypt (3.1.12 )
46
52
bootsnap (1.3.2 )
47
53
msgpack (~> 1.0 )
48
54
builder (3.2.3 )
49
55
byebug (10.0.2 )
56
+ case_transform (0.2 )
57
+ activesupport
50
58
concurrent-ruby (1.1.3 )
51
59
crass (1.0.4 )
52
60
erubi (1.7.1 )
55
63
activesupport (>= 4.2.0 )
56
64
i18n (1.1.1 )
57
65
concurrent-ruby (~> 1.0 )
66
+ jsonapi-renderer (0.2.0 )
58
67
listen (3.1.5 )
59
68
rb-fsevent (~> 0.9 , >= 0.9.4 )
60
69
rb-inotify (~> 0.9 , >= 0.9.7 )
@@ -134,6 +143,8 @@ PLATFORMS
134
143
ruby
135
144
136
145
DEPENDENCIES
146
+ active_model_serializers
147
+ bcrypt (~> 3.1.7 )
137
148
bootsnap (>= 1.1.0 )
138
149
byebug
139
150
listen (>= 3.0.5 , < 3.2 )
Original file line number Diff line number Diff line change
1
+ class UsersController < ApplicationController
2
+
3
+ # POST /register
4
+ def register
5
+ @user = User . create ( user_params )
6
+ if @user . save
7
+ response = { message : 'User created successfully' }
8
+ render json : response , status : :created
9
+ else
10
+ render json : @user . errors , status : :bad
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def user_params
17
+ params . permit (
18
+ :name ,
19
+ :email ,
20
+ :password
21
+ )
22
+ end
23
+ end
Original file line number Diff line number Diff line change
1
+ class User < ApplicationRecord
2
+ #Validations
3
+ validates_presence_of :name , :email , :password_digest
4
+ validates :email , uniqueness : true
5
+
6
+ #encrypt password
7
+ has_secure_password
8
+ end
Original file line number Diff line number Diff line change
1
+ class MovieSerializer < ActiveModel ::Serializer
2
+ attributes :id
3
+ end
Original file line number Diff line number Diff line change 1
- import React , { Component } from ' react' ;
1
+ import React , { Component } from " react" ;
2
2
3
3
class Button extends Component {
4
-
5
4
state = {
5
+ results : [ ]
6
+ } ;
6
7
7
- results : [ ]
8
- }
9
-
10
-
11
- callApi = async ( ) => {
12
-
13
- const api_call = await fetch ( 'http://localhost:3000/api/v1/movies' ) ;
8
+ callApi = async ( ) => {
9
+ const api_call = await fetch ( "http://localhost:3000/api/v1/movies" ) ;
14
10
15
- const data = await api_call . json ( ) ;
16
-
17
- this . setState ( {
18
-
19
- results : data
20
- } ) ;
21
- }
11
+ const data = await api_call . json ( ) ;
22
12
13
+ this . setState ( {
14
+ results : data
15
+ } ) ;
16
+ } ;
23
17
24
18
render ( ) {
25
-
26
19
return (
27
20
< div >
28
- < div className = "card container mt-3" >
21
+ < div className = "card container mt-3" >
29
22
< div className = "card-body" >
30
23
< div className = "row" >
31
- < center >
32
- < button className = "btn btn-primary" onClick = { this . callApi } > Test Call!</ button > < br />
33
- </ center > < br /> < br /> < br /> < br /> < br />
34
- < p className = "m-5" > { this . state . results . map ( ( obj ) => < li > { obj . name } </ li > ) } </ p >
24
+ < center >
25
+ < button className = "btn btn-primary" onClick = { this . callApi } >
26
+ Test Call!
27
+ </ button >
28
+ < br />
29
+ </ center >
30
+ < br />
31
+ < br />
32
+ < br />
33
+ < br />
34
+ < br />
35
+ < p className = "m-5" >
36
+ { this . state . results . map ( obj => (
37
+ < li > { obj . name } </ li >
38
+ ) ) }
39
+ </ p >
35
40
</ div >
36
41
</ div >
37
42
</ div >
Original file line number Diff line number Diff line change
1
+ class CreateUsers < ActiveRecord ::Migration [ 5.2 ]
2
+ def change
3
+ create_table :users do |t |
4
+ t . string :name
5
+ t . string :email
6
+ t . string :password_digest
7
+
8
+ t . timestamps
9
+ end
10
+ end
11
+ end
Original file line number Diff line number Diff line change 10
10
#
11
11
# It's strongly recommended that you check this file into your version control system.
12
12
13
- ActiveRecord ::Schema . define ( version : 2018_11_12_213959 ) do
13
+ ActiveRecord ::Schema . define ( version : 2018_11_28_092508 ) do
14
14
15
15
create_table "movies" , force : :cascade do |t |
16
16
t . string "name"
19
19
t . datetime "updated_at" , null : false
20
20
end
21
21
22
+ create_table "users" , force : :cascade do |t |
23
+ t . string "name"
24
+ t . string "email"
25
+ t . string "password_digest"
26
+ t . datetime "created_at" , null : false
27
+ t . datetime "updated_at" , null : false
28
+ end
29
+
22
30
end
You can’t perform that action at this time.
0 commit comments