-
Notifications
You must be signed in to change notification settings - Fork 12
Chapter 8 #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Chapter 8 #7
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
defaults |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,78 @@ | ||
# See https://help.github.com/articles/ignoring-files for more about ignoring files. | ||
# | ||
# If you find yourself ignoring temporary files generated by your text editor | ||
# or operating system, you probably want to add a global ignore instead: | ||
# git config --global core.excludesfile '~/.gitignore_global' | ||
|
||
# Ignore bundler config. | ||
/.bundle | ||
*.rbc | ||
capybara-*.html | ||
.rspec | ||
/db/*.sqlite3 | ||
/db/*.sqlite3-journal | ||
/db/*.sqlite3-[0-9]* | ||
/public/system | ||
/coverage/ | ||
/spec/tmp | ||
*.orig | ||
rerun.txt | ||
pickle-email-*.html | ||
|
||
# Ignore all logfiles and tempfiles. | ||
/log/* | ||
/tmp/* | ||
!/log/.keep | ||
!/tmp/.keep | ||
|
||
# Ignore pidfiles, but keep the directory. | ||
/tmp/pids/* | ||
!/tmp/pids/ | ||
!/tmp/pids/.keep | ||
# TODO Comment out this rule if you are OK with secrets being uploaded to the repo | ||
config/initializers/secret_token.rb | ||
config/master.key | ||
|
||
# Ignore uploaded files in development. | ||
/storage/* | ||
!/storage/.keep | ||
/tmp/storage/* | ||
!/tmp/storage/ | ||
!/tmp/storage/.keep | ||
# Only include if you have production secrets in this file, which is no longer a Rails default | ||
# config/secrets.yml | ||
|
||
# dotenv, dotenv-rails | ||
# TODO Comment out these rules if environment variables can be committed | ||
.env | ||
.env*.local | ||
|
||
## Environment normalization: | ||
/.bundle | ||
/vendor/bundle | ||
|
||
# these should all be checked in to normalize the environment: | ||
# Gemfile.lock, .ruby-version, .ruby-gemset | ||
|
||
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: | ||
.rvmrc | ||
|
||
# if using bower-rails ignore default bower_components path bower.json files | ||
/vendor/assets/bower_components | ||
*.bowerrc | ||
bower.json | ||
|
||
# Ignore pow environment settings | ||
.powenv | ||
|
||
# Ignore Byebug command history file. | ||
.byebug_history | ||
|
||
# Ignore node_modules | ||
node_modules/ | ||
|
||
# Ignore precompiled javascript packs | ||
/public/packs | ||
/public/packs-test | ||
/public/assets | ||
|
||
# Ignore master key for decrypting credentials and more. | ||
/config/master.key | ||
/config/database.yml | ||
/test/* | ||
# Ignore yarn files | ||
/yarn-error.log | ||
yarn-debug.log* | ||
.yarn-integrity | ||
|
||
# Ignore uploaded files in development | ||
/storage/* | ||
!/storage/.keep | ||
/public/uploads | ||
|
||
/public/packs | ||
/public/packs-test | ||
/node_modules | ||
/yarn-error.log | ||
yarn-debug.log* | ||
.yarn-integrity | ||
config/database.yml | ||
config/database.yml |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@import "bootstrap"; | ||
|
||
|
||
.navbar-brand { | ||
text-transform: uppercase; | ||
letter-spacing: 0.1em; | ||
font-weight: bold; | ||
} | ||
|
||
/* Tăng kích cỡ chữ cho h1 */ | ||
h1 { | ||
font-size: 2.5rem; | ||
} | ||
|
||
@import "custom"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// app/assets/stylesheets/custom.scss | ||
body { | ||
background-color: #f8f9fa; | ||
} | ||
/* sidebar */ | ||
aside { | ||
section.user_info { | ||
margin-top: 20px; | ||
} | ||
section { | ||
padding: 10px 0; | ||
margin-top: 20px; | ||
|
||
&:first-child { | ||
border: 0; | ||
padding-top: 0;} | ||
|
||
span { | ||
display: block; | ||
margin-bottom: 3px; | ||
line-height: 1; | ||
} | ||
h1 { | ||
font-size: 1.4em; | ||
text-align: left; | ||
letter-spacing: -1px; | ||
margin-bottom: 3px; | ||
margin-top: 0px;} | ||
} | ||
} | ||
.gravatar { | ||
float: left; | ||
margin-right: 10px; | ||
} | ||
.gravatar_edit {margin-top: 15px;} | ||
|
||
|
||
/* forms */ | ||
input, textarea, select, .uneditable-input { | ||
border: 1px solid #bbb; | ||
width: 100%;margin-bottom: 15px; | ||
} | ||
input { | ||
height: auto !important;} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
class ApplicationController < ActionController::Base | ||
include SessionsHelper | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class PagesController < ApplicationController | ||
def home | ||
end | ||
|
||
def help | ||
end | ||
|
||
def contact | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class SessionsController < ApplicationController | ||
def new | ||
|
||
# Cookie thong thuong | ||
cookies[:demo_normal] = "normal" | ||
|
||
# Gia tri cua cookie se duoc ma hoa | ||
# Cookie nay duoc ma hoa voi key la "secret.secret_key_base" | ||
cookies.signed[:demo_signed] = "signed" | ||
|
||
# Gia tri cua cookie se duoc ma hoa tuong tu nhu cookies.signed | ||
# Cookie nay duoc ma hoa voi key la "secret.secret_key_base" | ||
cookies.encrypted[:demo_encrypted] = "encrypted" | ||
|
||
# Khi dung httponly, cookie se khong the doc duoc bang JavaScript, | ||
# va cookie se het han sau thoi gian | ||
cookies[:demo_httponly] = {value: "http only", expires: Time.current + 1.hour, httponly: true } | ||
Rails.logger.info "Đã set cookie demo_httponly với HttpOnly" | ||
# Phần code khác... | ||
# Khi dung cookies.permanent, cookie nay se het han sau mot thoi gian rat dai, khoang 20 nam tu thoi | ||
cookies.permanent[:demo_permanent] = "permanent" | ||
end | ||
|
||
def create | ||
user = User.find_by(email: params.dig(:session, :email)&.downcase) | ||
if user && user.authenticate(params.dig(:session, :password)) | ||
log_in user # Đây sẽ thiết lập session[:user_id] = user.id | ||
redirect_to user | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thêm flash msg báo login thành công nữa đi e |
||
else | ||
flash.now[:danger] = t "invalid_email_password_combination" | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
log_out | ||
redirect_to root_path | ||
end | ||
end |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,28 @@ | ||||||
class UsersController < ApplicationController | ||||||
def show | ||||||
@user = User.find_by id: params[:id] | ||||||
unless @user | ||||||
flash[:error] = "User not found." | ||||||
redirect_to root_path and return | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mặc định line cuối cùng trong method là ruby tự return rồi em, ko cần khai báo
Suggested change
|
||||||
end | ||||||
end | ||||||
def new | ||||||
@user = User.new | ||||||
end | ||||||
def create | ||||||
@user = User.new(user_params) | ||||||
#byebug | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ko có để byebug lại nhé, xóa lun e |
||||||
if @user.save | ||||||
# do something | ||||||
log_in @user | ||||||
flash[:success] = "User created successufully!" | ||||||
redirect_to @user | ||||||
else | ||||||
render :new | ||||||
end | ||||||
end | ||||||
private | ||||||
def user_params | ||||||
params.require(:user).permit(:name, :email, :password, :password_confirmation, :birthday, :gender) | ||||||
end | ||||||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lỗi end line nè em, thêm line trống vào cuối file này