Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sample_app
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nguyen Hoang Mai Phuong
sample_app
Commits
b747d7ba
Commit
b747d7ba
authored
Jun 28, 2021
by
Nguyen Hoang Mai Phuong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix style code
parent
bc83113d
Pipeline
#1317
canceled with stages
in 0 seconds
Changes
9
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
60 additions
and
10 deletions
+60
-10
app/controllers/users_controller.rb
+3
-3
app/models/micropost.rb
+4
-0
app/views/password_resets/edit.html.erb
+1
-2
app/views/password_resets/new.html.erb
+1
-2
app/views/user_mailer/password_reset.html.erb
+2
-2
db/migrate/20210628090605_create_microposts.rb
+11
-0
db/schema.rb
+11
-1
test/fixtures/microposts.yml
+9
-0
test/models/micropost_test.rb
+18
-0
No files found.
app/controllers/users_controller.rb
View file @
b747d7ba
...
@@ -6,12 +6,12 @@ class UsersController < ApplicationController
...
@@ -6,12 +6,12 @@ class UsersController < ApplicationController
before_action
:admin_user
,
only: :destroy
before_action
:admin_user
,
only: :destroy
def
show
def
show
@user
=
User
.
find
(
params
[
:id
]
)
@user
=
User
.
find
(
params
[
:id
]
)
redirect_to
root_url
and
return
unless
true
redirect_to
root_url
and
return
unless
true
end
end
def
index
def
index
@users
=
User
.
where
(
activated:
true
)
.
paginate
(
page:
params
[
:page
]
)
@users
=
User
.
where
(
activated:
true
).
paginate
(
page:
params
[
:page
]
)
end
end
def
new
def
new
...
@@ -49,7 +49,7 @@ class UsersController < ApplicationController
...
@@ -49,7 +49,7 @@ class UsersController < ApplicationController
redirect_to
users_url
redirect_to
users_url
end
end
private
private
def
user_params
def
user_params
params
.
require
(
:user
).
permit
(
:name
,
:email
,
:password
,
:password_confirmation
)
params
.
require
(
:user
).
permit
(
:name
,
:email
,
:password
,
:password_confirmation
)
...
...
app/models/micropost.rb
0 → 100644
View file @
b747d7ba
class
Micropost
<
ApplicationRecord
belongs_to
:user
validates
:content
,
presence:
true
,
length:
{
maximum:
140
}
end
app/views/password_resets/edit.html.erb
View file @
b747d7ba
...
@@ -3,8 +3,7 @@
...
@@ -3,8 +3,7 @@
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-md-6 offset-3"
>
<div
class=
"col-md-6 offset-3"
>
<%=
form_with
(
model:
@user
,
url:
password_reset_path
(
params
[
:id
]),
<%=
form_with
(
model:
@user
,
url:
password_reset_path
(
params
[
:id
]),
local:
true
)
do
|
f
|
%>
local:
true
)
do
|
f
|
%>
<%=
render
'shared/error_messages'
%>
<%=
render
'shared/error_messages'
%>
<%=
hidden_field_tag
:email
,
@user
.
email
%>
<%=
hidden_field_tag
:email
,
@user
.
email
%>
...
...
app/views/password_resets/new.html.erb
View file @
b747d7ba
...
@@ -3,8 +3,7 @@
...
@@ -3,8 +3,7 @@
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-md-6 offset-3"
>
<div
class=
"col-md-6 offset-3"
>
<%=
form_with
(
url:
password_resets_path
,
scope: :password_reset
,
<%=
form_with
(
url:
password_resets_path
,
scope: :password_reset
,
local:
true
)
do
|
f
|
%>
local:
true
)
do
|
f
|
%>
<%=
f
.
label
:email
%>
<%=
f
.
label
:email
%>
<%=
f
.
email_field
:email
,
class:
'form-control'
%>
<%=
f
.
email_field
:email
,
class:
'form-control'
%>
<%=
f
.
submit
"Submit"
,
class:
"btn btn-primary"
%>
<%=
f
.
submit
"Submit"
,
class:
"btn btn-primary"
%>
...
...
app/views/user_mailer/password_reset.html.erb
View file @
b747d7ba
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
<p>
To reset your password click the link below:
</p>
<p>
To reset your password click the link below:
</p>
<%=
link_to
"Reset password"
,
edit_password_reset_url
(
@user
.
reset_token
,
<%=
link_to
"Reset password"
,
edit_password_reset_url
(
@user
.
reset_token
,
email:
email:
@user
.
email
)
%>
@user
.
email
)
%>
<p>
This link will expire in two hours.
</p>
<p>
This link will expire in two hours.
</p>
<p>
<p>
...
...
db/migrate/20210628090605_create_microposts.rb
0 → 100644
View file @
b747d7ba
class
CreateMicroposts
<
ActiveRecord
::
Migration
[
6.1
]
def
change
create_table
:microposts
do
|
t
|
t
.
text
:content
t
.
references
:user
,
null:
false
,
foreign_key:
true
t
.
timestamps
end
add_index
:microposts
,
[
:user_id
,
:created_at
]
end
end
db/schema.rb
View file @
b747d7ba
...
@@ -10,7 +10,16 @@
...
@@ -10,7 +10,16 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2021_06_28_041628
)
do
ActiveRecord
::
Schema
.
define
(
version:
2021_06_28_090605
)
do
create_table
"microposts"
,
force: :cascade
do
|
t
|
t
.
text
"content"
t
.
integer
"user_id"
,
null:
false
t
.
datetime
"created_at"
,
precision:
6
,
null:
false
t
.
datetime
"updated_at"
,
precision:
6
,
null:
false
t
.
index
[
"user_id"
,
"created_at"
],
name:
"index_microposts_on_user_id_and_created_at"
t
.
index
[
"user_id"
],
name:
"index_microposts_on_user_id"
end
create_table
"users"
,
force: :cascade
do
|
t
|
create_table
"users"
,
force: :cascade
do
|
t
|
t
.
string
"name"
t
.
string
"name"
...
@@ -28,4 +37,5 @@ ActiveRecord::Schema.define(version: 2021_06_28_041628) do
...
@@ -28,4 +37,5 @@ ActiveRecord::Schema.define(version: 2021_06_28_041628) do
t
.
index
[
"email"
],
name:
"index_users_on_email"
,
unique:
true
t
.
index
[
"email"
],
name:
"index_users_on_email"
,
unique:
true
end
end
add_foreign_key
"microposts"
,
"users"
end
end
test/fixtures/microposts.yml
0 → 100644
View file @
b747d7ba
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one
:
content
:
MyText
user
:
one
two
:
content
:
MyText
user
:
two
test/models/micropost_test.rb
0 → 100644
View file @
b747d7ba
require
"test_helper"
class
MicropostTest
<
ActiveSupport
::
TestCase
def
setup
@user
=
users
(
:michael
)
# This code is not idiomatically correct.
@micropost
=
Micropost
.
new
(
content:
"Lorem ipsum"
,
user_id:
@user
.
id
)
end
test
"should be valid"
do
assert
@micropost
.
valid?
end
test
"user id should be present"
do
@micropost
.
user_id
=
nil
assert_not
@micropost
.
valid?
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