Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 58 additions & 22 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,33 +1,69 @@
# 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
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ gem "tzinfo-data", platforms: %i(mingw mswin x64_mingw jruby)

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false
gem 'bcrypt', '3.1.18'

# Use Sass to process CSS
# gem "sassc-rails"
Expand Down Expand Up @@ -73,3 +74,6 @@ group :test do
gem "selenium-webdriver"
gem "webdrivers"
end

gem 'sassc-rails'

13 changes: 13 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ GEM
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
base64 (0.1.1)
bcrypt (3.1.18)
bindex (0.8.1)
bootsnap (1.16.0)
msgpack (~> 1.2)
Expand All @@ -90,6 +91,7 @@ GEM
irb (>= 1.5.0)
reline (>= 0.3.1)
erubi (1.12.0)
ffi (1.17.1-x86_64-linux-gnu)
globalid (1.1.0)
activesupport (>= 5.0)
i18n (1.14.1)
Expand Down Expand Up @@ -199,6 +201,14 @@ GEM
rubocop (>= 1.7.0, < 2.0)
ruby-progressbar (1.13.0)
rubyzip (2.3.2)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
selenium-webdriver (4.10.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
Expand All @@ -213,6 +223,7 @@ GEM
stimulus-rails (1.2.2)
railties (>= 6.0.0)
thor (1.2.2)
tilt (2.6.0)
timeout (0.4.0)
turbo-rails (1.4.0)
actionpack (>= 6.0.0)
Expand Down Expand Up @@ -242,6 +253,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
bcrypt (= 3.1.18)
bootsnap
capybara
debug
Expand All @@ -253,6 +265,7 @@ DEPENDENCIES
rubocop (~> 1.26)
rubocop-checkstyle_formatter
rubocop-rails (~> 2.14.0)
sassc-rails
selenium-webdriver
sprockets-rails
stimulus-rails
Expand Down
15 changes: 0 additions & 15 deletions app/assets/stylesheets/application.css

This file was deleted.

14 changes: 14 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@import "bootstrap/scss/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";
5 changes: 5 additions & 0 deletions app/assets/stylesheets/custom.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// app/assets/stylesheets/custom.scss
body {
background-color: #f8f9fa;
}

10 changes: 10 additions & 0 deletions app/controllers/pages_controller.rb
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
2 changes: 2 additions & 0 deletions app/helpers/pages_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module PagesHelper
end
8 changes: 5 additions & 3 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails"
import "controllers"

import "bootstrap";
import "bootstrap/dist/css/bootstrap.min.css";
import "popper.js";

13 changes: 13 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class User < ApplicationRecord
has_secure_password
validate :birthday_within_last_100years
private

def birthday_within_last_100years
return unless birthday.present?
if birthday < 100.years.ago.to_date
errors.add(:birthday, "must be within the last 100 years")
end
end

end
42 changes: 38 additions & 4 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,50 @@
<!DOCTYPE html>
<html>
<head>
<title>RailsTutorial</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<title><%= yield(:title) || "Sample App" %></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<!-- Gọi file CSS (đã bundle) -->
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
<!-- Gọi file JS (đã bundle) -->
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>

<!-- Bootstrap CDN -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>

<body>
<%= yield %>
<!-- Navbar Bootstrap 5 -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<%= link_to "SAMPLE APP", root_path, class: "navbar-brand" %>

<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<%= link_to "Home", root_path, class: "nav-link" %>
</li>
<li class="nav-item">
<%= link_to "Help", pages_help_path, class: "nav-link" %>
</li>
<li class="nav-item">
<%= link_to "Log in", "#", class: "nav-link" %>
</li>
</ul>
</div>
</div>
</nav>

<!-- Phần nội dung của từng trang con -->
<div class="container mt-4">
<%= yield %>
</div>
</body>
</html>
2 changes: 2 additions & 0 deletions app/views/pages/help.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Pages#help</h1>
<p>Find me in app/views/pages/help.html.erb</p>
14 changes: 14 additions & 0 deletions app/views/pages/home.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<% provide(:title, "Home") %>

<!-- Phần nền xám nhạt + căn giữa -->
<div class="bg-light w-100 py-5">
<div class="text-center">
<h1 class="display-4 fw-bold">Welcome to the Sample App</h1>
<p>
This is the home page for the
<a href="https://www.railstutorial.org/">Ruby on Rails Tutorial</a>
sample application.
</p>
<%= link_to "Sign up now!", "#", class: "btn btn-primary btn-lg" %>
</div>
</div>
13 changes: 13 additions & 0 deletions app/views/shared/_error_messages.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<% if @user.errors.any? %>
<div id="error_explanation">
<div class="alert alert-danger">
<%= t "the_form_contains" %>
<%= pluralize @user.errors.count, "error" %>.
</div>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
33 changes: 33 additions & 0 deletions app/views/users/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<% provide :title, "Signup" %>
<h1>Sign up </h1>
<div class= "row">
<div class= "col -md-6 col -md-offset-3">
<%= form_for @user, url: signup_path do |f| %>
<%= render "shared/error_messages"%>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :email %>
<%= f.email_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, t("confirmation") %>

<%= f.password_field :password_confirmation %>

<div class="form-group">
<%= f.label :birthday, "Birthday" %>
<%= f.date_select :birthday, start_year: Date.today.year - 100, end_year: Date.today.year, order: [:day, :month, :year], prompt: { day: 'Select Day', month: 'Select Month', year: 'Select Year' }, class: "form-control" %>
</div>

<div class="form-group">
<%= f.label :gender, "Gender" %>
<%= f.select :gender, options_for_select([['Female', 'female'], ['Male', 'male'], ['Other', 'other']], f.object.gender), { prompt: "Select Gender" }, class: "form-control" %>
</div>


<%= f.submit "Create my account", class: "btn btn-primary" %>
<% end %>
</div>



13 changes: 13 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<% provide :title, @user.name %>
<div class="row">
<aside class="col-md-4">
<section class="user_info">
<h1>
<%= gravatar_for @user %>
<%= @user.name %>
</h1>
</section>
</aside>
</div>


Loading