Skip to content

Commit 19bf789

Browse files
committed
Chapter 3, 4, 5
1 parent 12182eb commit 19bf789

File tree

13 files changed

+134
-11
lines changed

13 files changed

+134
-11
lines changed

Gemfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ gem "tzinfo-data", platforms: %i(mingw mswin x64_mingw jruby)
4343
gem "bootsnap", require: false
4444

4545
# Use Sass to process CSS
46-
# gem "sassc-rails"
46+
gem "sassc-rails"
47+
gem "bootstrap", "~> 5.3.2"
48+
4749

4850
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html]
4951
# gem "image_processing", "~> 1.2"

Gemfile.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ GEM
7373
bindex (0.8.1)
7474
bootsnap (1.16.0)
7575
msgpack (~> 1.2)
76+
bootstrap (5.3.5)
77+
popper_js (>= 2.11.8, < 3)
7678
builder (3.2.4)
7779
capybara (3.39.2)
7880
addressable
@@ -90,6 +92,7 @@ GEM
9092
irb (>= 1.5.0)
9193
reline (>= 0.3.1)
9294
erubi (1.12.0)
95+
ffi (1.17.2-x86_64-linux-gnu)
9396
globalid (1.1.0)
9497
activesupport (>= 5.0)
9598
i18n (1.14.1)
@@ -136,6 +139,7 @@ GEM
136139
parser (3.2.2.3)
137140
ast (~> 2.4.1)
138141
racc
142+
popper_js (2.11.8)
139143
public_suffix (5.0.3)
140144
puma (5.6.6)
141145
nio4r (~> 2.0)
@@ -199,6 +203,14 @@ GEM
199203
rubocop (>= 1.7.0, < 2.0)
200204
ruby-progressbar (1.13.0)
201205
rubyzip (2.3.2)
206+
sassc (2.4.0)
207+
ffi (~> 1.9)
208+
sassc-rails (2.1.2)
209+
railties (>= 4.0.0)
210+
sassc (>= 2.0)
211+
sprockets (> 3.0)
212+
sprockets-rails
213+
tilt
202214
selenium-webdriver (4.10.0)
203215
rexml (~> 3.2, >= 3.2.5)
204216
rubyzip (>= 1.2.2, < 3.0)
@@ -213,6 +225,7 @@ GEM
213225
stimulus-rails (1.2.2)
214226
railties (>= 6.0.0)
215227
thor (1.2.2)
228+
tilt (2.6.1)
216229
timeout (0.4.0)
217230
turbo-rails (1.4.0)
218231
actionpack (>= 6.0.0)
@@ -243,6 +256,7 @@ PLATFORMS
243256

244257
DEPENDENCIES
245258
bootsnap
259+
bootstrap (~> 5.3.2)
246260
capybara
247261
debug
248262
importmap-rails
@@ -253,6 +267,7 @@ DEPENDENCIES
253267
rubocop (~> 1.26)
254268
rubocop-checkstyle_formatter
255269
rubocop-rails (~> 2.14.0)
270+
sassc-rails
256271
selenium-webdriver
257272
sprockets-rails
258273
stimulus-rails

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,47 @@
11
# Rails tutorial - Sample App
22

33
# 1. Phiên bản cài đặt để chạy được dự án:
4+
45
- Ruby: 3.2.2
56
- Rails: 7.0.7
67
- MySQL
78

89
# 2. Hướng dẫn cài dự án:
10+
911
## 2.1 Cài đặt config(chỉ chạy lần đầu)
12+
1013
- Tạo config database cho dự án: cp config/database.yml.example config/database.yml
1114
- Chạy lệnh để tạo database: rails db:create
1215
- Bật server: rails s
13-
Truy cập đường dẫn http://localhost:3000/ hiển thị Rails là thành công
16+
Truy cập đường dẫn http://localhost:3000/ hiển thị Rails là thành công
17+
18+
1. Research gem config
19+
20+
- gem config là gem dùng để quản lý biến cấu hình trong Rails/Ruby một cách gọn gàng, dễ maintain
21+
- Thay vì hardcode hoặc phụ thuộc ENV, có thể:
22+
- Tạo file config/settings.yml hoặc settings.local.yml để lưu cấu hình.
23+
- Truy cập dễ dàng qua Settings.api_key hoặc Settings[:api_key]
24+
25+
2. Research I18n, I18n lazy lookup
26+
27+
- I18n (Internationalization) trong Rails cho phép ứng dụng hỗ trợ đa ngôn ngữ.
28+
- Các chuỗi văn bản được lưu trong config/locales/\*.yml
29+
- Rails tự động load theo I18n.locale
30+
31+
3. What is Attack CSRF, XSS? and How to prevent them in Rails?
32+
33+
- CSRF : Là tấn công khi attacker giả mạo request của user đã authenticated.
34+
- Ví dụ: attacker gửi form POST từ site khác, user đang login sẽ thực hiện hành động trái phép.
35+
36+
4. XSS (Cross-Site Scripting)
37+
38+
- Là tấn công chèn script độc hại vào trang web, ví dụ:
39+
- Ví dụ: <script>alert("Hacked!")</script>
40+
- Để tránh XSS, sử dụng Rails helper như: sanitize, html_escape, raw
1441

42+
5. Distinguish: nil?, empty?, blank?, present?
43+
6. Presenting the effect of helper folder, what case of using it
1544

45+
- app/helpers/ chứa các module helper hỗ trợ xử lý logic hiển thị trong view.
46+
- Tác dụng: tách logic view và controller, dễ maintain, dễ debug,
47+
Giúp giữ view gọn gàng, tách biệt logic format ra khỏi template.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/*
2+
*= require_tree .
3+
*= require_self
4+
*/

app/assets/stylesheets/custom.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@import "bootstrap";
2+
body {
3+
padding-top: 60px;
4+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class StaticPagesController < ApplicationController
2+
def home
3+
end
4+
5+
def help
6+
end
7+
8+
def contact
9+
end
10+
11+
end

app/helpers/static_pages_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module StaticPagesHelper
2+
end
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>RailsTutorial</title>
5-
<meta name="viewport" content="width=device-width,initial-scale=1">
4+
<title><%= yield(:title) || "Ruby on Rails Tutorial Sample App" %></title>
65
<%= csrf_meta_tags %>
76
<%= csp_meta_tag %>
87

98
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
10-
<%= javascript_importmap_tags %>
9+
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
1110
</head>
1211

1312
<body>
14-
<%= yield %>
13+
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
14+
<div class="container">
15+
<a class="navbar-brand" href="/">Sample App</a>
16+
<div>
17+
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
18+
<li class="nav-item"><a class="nav-link" href="/">Home</a></li>
19+
<li class="nav-item"><a class="nav-link" href="/help">Help</a></li>
20+
<li class="nav-item"><a class="nav-link" href="/contact">Contact</a></li>
21+
</ul>
22+
</div>
23+
</div>
24+
</nav>
25+
26+
<div class="container">
27+
<%= yield %>
28+
</div>
1529
</body>
1630
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<% provide(:title, "Contact | Ruby on Rails Tutorial Sample App") %>
2+
<h1>Contact</h1>
3+
<p>Hello, YourName</p>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Help | Ruby on Rails Tutorial Sample App</title>
5+
</head>
6+
<body>
7+
<h1>Help</h1>
8+
9+
<p>
10+
Get help on the Ruby on Rails Tutorial at the
11+
<a href="http://www.railstutorial.org/help">Rails Tutorial help page</a>.
12+
To get help on this sample app, see the
13+
<a href="http://www.railstutorial.org/book">
14+
<em>Ruby on Rails Tutorial</em> book
15+
</a>.
16+
</p>
17+
</body>
18+
</html>

0 commit comments

Comments
 (0)