Rails philosophy includes 2 major guiding principles:
- Don’t Repeat Yourself (DRY).
- Convention Over Configuration.
Create a new Rails project
Directory of Rails application
Some command:
rails server | rails s
rails c | rails c --sandbox
rails generate | rails g
rails db:migrate
MVC in Rails
Model: Responsible for representing business data and logic.
“A controller's purpose is to receive specific requests for the application. Routing decides which
controller receives which requests. Often, there is more than one route to each controller, and
different routes can be served by different actions. Each action's purpose is to collect information to
provide it to a view.”
=> Controller nhận các request cụ thể đến ứng dụng. Routing quyết định controller nào sẽ xử lý
request đó. Thông thường, có nhiều hơn một routing đến mỗi controller, và mỗi route khác nhau sẽ
tương ứng bởi những action khác nhau. Mỗi action thu thập thông tin để cung cấp đến cho view.
“A view's purpose is to display this information in a human readable format. An important
distinction to make is that it is the controller, not the view, where information is collected. The view
should just display that information. By default, view templates are written in a language called
eRuby (Embedded Ruby) which is processed by the request cycle in Rails before being sent to the
user.”
=> View thể hiện thông tin đến cho người dùng. Template được viết bởi ngôn ngữ erb.
<%= %> => print
<% %> => execute
Name convention for model name, controller name
form_with helper to create form in Rails
http_basic_authenticate_with method, which allows access to the requested action if that method
allows it.
link_to method , create hyperlink based on text to display.
Gem Devise and Authlogic are used to authenticate.