Professional Documents
Culture Documents
Puter Based Technologies - TA.NguyenDucAnh PDF
Puter Based Technologies - TA.NguyenDucAnh PDF
Internet
Web-based technologies
Mobile apps
AI
Blockchain
Big Data
…
3 Technology Application in real life
E-Commerce site
Game
Social platforms
Self-driving car
eKyc system
Banking system
…
4
5
6
7
8
9
10
11
12 About the course
1. Theory
2. Tutorial
3. Practice
15 Assessment
Email: duc4nh.nguyen@gmail.com
1. Introduction to web
17
development project
18 Web Application Architecture
19 Key Concepts
Frontend is everything you see and can interact with using a browser.
The front-end is built using a combination of technologies such as HTML,
JavaScript and CSS
Backend, also called the server-side, consists of the server which
provides data on request, the application that channels it, and the
database which organizes the information.
Web server: a computer that stores web server software and a website's
component files
Database is an organized collection of structured information, or data
(popular databases being used are MySQL, SQLite, Postgres, etc)
File system handles the persistent storage of data files, apps, and the
files associated with the operating system itself
20 Web Application Architecture Diagram
21 Preparation before next class
Follow this article, install Ruby, Rails & SQLite (you can
ignore other parts)
For window user: also refer to this to install SQLite
Noted: the required version is as below:
ruby 3.1.2 (for window user: find this version here)
Rails 7.0.4
23 Verify that your packages are installed
ruby -v
rails -v
sqlite3 --version
24
2. How to prototype ideas
25 User story
User story 1:
a. As an bookkeeper
b. I want to see the list of all books available in my library
c. So that, I can monitor the books availability
d. Acceptance criteria:
Book list in a table
Data shown to be: title, publisher, year, status of the
book (in stock/ lent?)
28 Sample application topics
Restaurant management
Supermarket management system
Food recipe management
Bookstore management
Dairy app
Warehouse management
Bus management
Civil management
Car parking management
Train line operating system
HR application
etc…
29 Class exercise
Mac: Click the Launchpad icon in the Dock, type Terminal in the
search field, then click Terminal
Window: Click Start and search for "Command Prompt" or type
"cmd" and then click OK.
33 Ruby
Ruby is a
open-source
object-oriented
scripting
interpreted
high-level
programming language
34 Rails
ruby -v
rails -v
sqlite3 --version
39
4. Generate a starter project
40 Creating the Application
On a terminal, let start with:
rails new <your-app-name>
Your app name should be: [your name]-[student-id]-[your topic].
Follow this convention as this will be a part of your final submission.
e.g: nguyen-duc-anh-0123456789-library-system
41 Start the server
cd <your-app-name>
rails server
42 Hello, Rails!
On your browser: go to http://127.0.0.1:3000
Confirm that your app is running
43 Introducing Code Editor & IDE
Code editors are tools typically used by programmers and web developers to
write and edit code
e.g: Sublime
Feel free to select a code editor or IDE of your choice! A good one will help you
speed up development process a LOT.
5. Database design and
44
implementation
45 Defining Models
Term Model in Rails is used to describing data structures and the
methods to access them in general.
In rails with an SQL database
A model class represent a table
Model attributes represent columns
Model objects represent rows
46 Defining Models (2)
47 Defining Model Associations
In Rails, an association is a connection between two models.
For example, a model for authors and a model for books. Each
author can have many books.
One-to-One
One-to-Many
Many-to-Many
48 Sketching database schema
Draw.io
49 Class exercise
rails db:migrate
rails server
53 Understand CRUD in your Rails application
CRUD refers to the four basic operations a software application should be
able to perform – Create, Read, Update, and Delete.
The CREATE operation adds a new record to a database.
READ returns records (or documents or items) from a database table (or
collection or bucket) based on some search criteria.
UPDATE is used to modify existing records in the database. For example, this can
be the change of address in a customer database or price change in a product
database.
DELETE operations allow the user to remove records from the database. A hard
delete removes the record altogether, while a soft delete flags the record but
leaves it in place.
54 Class exercise
rails db:migrate
60 Restart the app
yarn build
yarn build:css
rails server
Note for Window user: due to cmd syntax, we need to make a slight
change to package.json file as below:
61 Try out the new template!
By far, the most widely used modern version control system in the
world today is Git.
Developers who have worked with Git are well represented in the
pool of available software development talent
Read More about Git (vietnamese)
Installing Git
66 Create Github Account & Github Project
We want verify the attributes of Book & Subject are valid, e.g:
Subject must has name
A book must has title, author, year & publisher
Title of the book must be unique
Year of a book must be a number
Year of a book must not be in the future
74 Data Validation
app/models/book.rb
validates_presence_of :title, :author, :publisher
validates_uniqueness_of :title
validates_numericality_of :year
app/models/subject.rb
validates_presence_of :name
75 Data Validation
Custom validator
validate :year_up_to_present
def year_up_to_present
errors.add(:field_name, 'Year must not be in the future') if year >
Time.now.year
end
76 Data Association
git status
git add -A
git commit -m "Add model validation and association"
git push origin master
79 Class exercise
Let polish a few thing for our app, which include but not limit to:
a. Update root url
b. Show model association name
c. Select box for association
d. Add logo of our own
e. Add links to Menu
f. Update website title
81 Update root url
With
<%= form.select :subject_id, options_from_collection_for_select(
Subject.all, 'id', 'name', selected = book.subject_id), class: label_class %>
85 Add logo of our own
<%= link_to "Books", "/books", class: "p-3 hover:bg-gray-50 transition ease duration-300
rounded-lg text-center focus:bg-gray-100 lg:inline-block block" %>
<%= link_to "Subjects", "/subjects", class: "p-3 hover:bg-gray-50 transition ease duration-300
rounded-lg text-center focus:bg-gray-100 lg:inline-block block" %>
87 Remember to Save your code on Github!
git status
git add -A
git commit -m "Polishing plate boiler content"
git push origin master
88 Class exercise
git status
git add -A
git commit -m "Add rails admin"
git push origin master
93 Class exercise
Procfile is where you declare the one or more processes to be run for
your app to function
At root directory, create a new file named Procfile:
git status
git add -A
git commit -m "Config for Railway deployment"
git push origin master
103 Generate a project on Railway
Uhh ohh, our app is not running. It says Blocked host error!
No worry, Blocked Host is a feature of Rails to guard against DNS
rebinding attacks.
109 Config hosting
git status
git add -A
git commit -m "Config for blocked hosting"
git push origin master
111 Application on the Cloud!
Once our new code pushed to Github, go back to the site url and
you should see the deployment on Railway happen automatically.
Once deploy finish, our application should be available on the
cloud!
112 Class exercise