Skip to content

Commit df05111

Browse files
NguyenThanhHaNguyenThanhHa
authored andcommitted
chapter_3_4_5
1 parent 1ab878a commit df05111

File tree

10 files changed

+201
-22
lines changed

10 files changed

+201
-22
lines changed

.gitignore

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,69 @@
1-
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
2-
#
3-
# If you find yourself ignoring temporary files generated by your text editor
4-
# or operating system, you probably want to add a global ignore instead:
5-
# git config --global core.excludesfile '~/.gitignore_global'
6-
7-
# Ignore bundler config.
8-
/.bundle
1+
*.rbc
2+
capybara-*.html
3+
.rspec
4+
/db/*.sqlite3
5+
/db/*.sqlite3-journal
6+
/db/*.sqlite3-[0-9]*
7+
/public/system
8+
/coverage/
9+
/spec/tmp
10+
*.orig
11+
rerun.txt
12+
pickle-email-*.html
913

1014
# Ignore all logfiles and tempfiles.
1115
/log/*
1216
/tmp/*
1317
!/log/.keep
1418
!/tmp/.keep
1519

16-
# Ignore pidfiles, but keep the directory.
17-
/tmp/pids/*
18-
!/tmp/pids/
19-
!/tmp/pids/.keep
20+
# TODO Comment out this rule if you are OK with secrets being uploaded to the repo
21+
config/initializers/secret_token.rb
22+
config/master.key
2023

21-
# Ignore uploaded files in development.
22-
/storage/*
23-
!/storage/.keep
24-
/tmp/storage/*
25-
!/tmp/storage/
26-
!/tmp/storage/.keep
24+
# Only include if you have production secrets in this file, which is no longer a Rails default
25+
# config/secrets.yml
26+
27+
# dotenv, dotenv-rails
28+
# TODO Comment out these rules if environment variables can be committed
29+
.env
30+
.env*.local
31+
32+
## Environment normalization:
33+
/.bundle
34+
/vendor/bundle
35+
36+
# these should all be checked in to normalize the environment:
37+
# Gemfile.lock, .ruby-version, .ruby-gemset
2738

39+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
40+
.rvmrc
41+
42+
# if using bower-rails ignore default bower_components path bower.json files
43+
/vendor/assets/bower_components
44+
*.bowerrc
45+
bower.json
46+
47+
# Ignore pow environment settings
48+
.powenv
49+
50+
# Ignore Byebug command history file.
51+
.byebug_history
52+
53+
# Ignore node_modules
54+
node_modules/
55+
56+
# Ignore precompiled javascript packs
57+
/public/packs
58+
/public/packs-test
2859
/public/assets
2960

30-
# Ignore master key for decrypting credentials and more.
31-
/config/master.key
32-
/config/database.yml
33-
/test/*
61+
# Ignore yarn files
62+
/yarn-error.log
63+
yarn-debug.log*
64+
.yarn-integrity
65+
66+
# Ignore uploaded files in development
67+
/storage/*
68+
!/storage/.keep
69+
/public/uploads
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<% if @user.errors.any? %>
2+
<div id="error_explanation">
3+
<div class="alert alert-danger">
4+
<%= t "the_form_contains" %>
5+
<%= pluralize @user.errors.count, "error" %>.
6+
</div>
7+
<ul>
8+
<% @user.errors.full_messages.each do |msg| %>
9+
<li><%= msg %></li>
10+
<% end %>
11+
</ul>
12+
</div>
13+
<% end %>

app/views/users/new.html.erb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<% provide :title, "Signup" %>
2+
<h1>Sign up </h1>
3+
<div class= "row">
4+
<div class= "col -md-6 col -md-offset-3">
5+
<%= form_for @user, url: signup_path do |f| %>
6+
<%= render "shared/error_messages"%>
7+
<%= f.label :name %>
8+
<%= f.text_field :name %>
9+
<%= f.label :email %>
10+
<%= f.email_field :email %>
11+
<%= f.label :password %>
12+
<%= f.password_field :password %>
13+
<%= f.label :password_confirmation, t("confirmation") %>
14+
15+
<%= f.password_field :password_confirmation %>
16+
17+
<div class="form-group">
18+
<%= f.label :birthday, "Birthday" %>
19+
<%= 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" %>
20+
</div>
21+
22+
<div class="form-group">
23+
<%= f.label :gender, "Gender" %>
24+
<%= f.select :gender, options_for_select([['Female', 'female'], ['Male', 'male'], ['Other', 'other']], f.object.gender), { prompt: "Select Gender" }, class: "form-control" %>
25+
</div>
26+
27+
28+
<%= f.submit "Create my account", class: "btn btn-primary" %>
29+
<% end %>
30+
</div>
31+
32+
33+

app/views/users/show.html.erb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<% provide :title, @user.name %>
2+
<div class="row">
3+
<aside class="col-md-4">
4+
<section class="user_info">
5+
<h1>
6+
<%= gravatar_for @user %>
7+
<%= @user.name %>
8+
</h1>
9+
</section>
10+
</aside>
11+
</div>
12+
13+

config/database.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# MySQL. Versions 5.5.8 and up are supported.
2+
#
3+
# Install the MySQL driver
4+
# gem install mysql2
5+
#
6+
# Ensure the MySQL gem is defined in your Gemfile
7+
# gem "mysql2"
8+
#
9+
# And be sure to use new-style password hashing:
10+
# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
11+
#
12+
default: &default
13+
adapter: mysql2
14+
encoding: utf8mb4
15+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
16+
username: root
17+
password: "nguyenthanhha"
18+
socket: /var/run/mysqld/mysqld.sock
19+
20+
development:
21+
<<: *default
22+
database: rails_tutorial_development
23+
24+
# Warning: The database defined as "test" will be erased and
25+
# re-generated from your development database when you run "rake".
26+
# Do not set this db to the same as development or production.
27+
test:
28+
<<: *default
29+
database: rails_tutorial_test
30+
31+
# As with config/credentials.yml, you never want to store sensitive information,
32+
# like your database password, in your source code. If your source code is
33+
# ever seen by anyone, they now have access to your database.
34+
#
35+
# Instead, provide the password or a full connection URL as an environment
36+
# variable when you boot the app. For example:
37+
#
38+
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
39+
#
40+
# If the connection URL is provided in the special DATABASE_URL environment
41+
# variable, Rails will automatically merge its configuration values on top of
42+
# the values provided in this file. Alternatively, you can specify a connection
43+
# URL environment variable explicitly:
44+
#
45+
# production:
46+
# url: <%= ENV["MY_APP_DATABASE_URL"] %>
47+
#
48+
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
49+
# for a full overview on how database connection configuration can be specified.
50+
#
51+
production:
52+
<<: *default
53+
database: rails_tutorial_production
54+
username: rails_tutorial
55+
password: <%= ENV["RAILS_TUTORIAL_DATABASE_PASSWORD"] %>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require "test_helper"
2+
3+
class PagesControllerTest < ActionDispatch::IntegrationTest
4+
test "should get home" do
5+
get pages_home_url
6+
assert_response :success
7+
end
8+
9+
test "should get help" do
10+
get pages_help_url
11+
assert_response :success
12+
end
13+
end

test/fixtures/users.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2+
3+
one:
4+
name: MyString
5+
email: MyString
6+
7+
two:
8+
name: MyString
9+
email: MyString

test/models/user_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "test_helper"
2+
3+
class UserTest < ActiveSupport::TestCase
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
end

tmp/pids/.keep

Whitespace-only changes.

tmp/storage/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)