网站没有索引量是什么意思,网站后台不显示验证码,一个域名建多个网站,网络广告图片突然想跟着官方文档把Ruby On Rails过一遍#xff0c;把一些有用的记下来就可以一直看了#xff0c;do它! https://guides.rubyonrails.org/v7.2/
注#xff1a;官网是英文文档#xff0c;我自己翻译了一下#xff0c;不确保完全准确#xff0c;只供自己学习开发使用。 …突然想跟着官方文档把Ruby On Rails过一遍把一些有用的记下来就可以一直看了do它! https://guides.rubyonrails.org/v7.2/
注官网是英文文档我自己翻译了一下不确保完全准确只供自己学习开发使用。
Rails is a web application framework running on the Ruby programming language. There are several curated lists of online resources for learning Ruby:
Official Ruby Programming Language websiteList of Free Programming Books
1.Rails 是什么
Rails是一个由Ruby编程语言编写的Web应用开发框架。它是为了让编写Web应用更简单而设计
2. Say Hello, Rails
在完成安装启动后想开始写代码了you need to create at minimum a route, a controller with an action, and a view. A route将请求映射到controller action; A controller action里有处理请求的工作以及给View准备的数据。A view根据需要的格式显示数据。
Step1 在routes文件里添加一个route
Rails.application.routes.draw doget /articles, to: articles#index# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end这个route声明将GET /articles请求映射到ArticlesController 的index action.
Step2 通过下面这个命令生成ArticlesController和index
bin/rails generate controller Articles index --skip-routes生成的文件长这样app/controllers/articles_controller.rb
class ArticlesController ApplicationControllerdef indexend
end默认情况下Rails会自动render与controller 和 action名字相同的view即app/views/articles/index.html.erb
Step3 在index.html.erb文件里写上
h1Hello, Rails!/h1接下来启动server访问http://localhost:3000/articles就可以了。
也可以通过添加route
root articles#index
将其设置成home page, 即访问http://localhost:3000就能打开index.html.erb文件.
3. 生成一个Model
上述提到routes, controllers, actions, and views这些都是遵循MVC (Model-View-Controller)模式的Web应用典型组成部分。我们已经拥有了Controller和View,继续生成一个Model吧。
A model is a Ruby class that is used to represent data. Additionally, models can interact with the applications database through a feature of Rails called Active Record.
英文原文太好了不翻译了。可以跟官网一样用model generator也可以自己创建app/models/article.rb。
可以根据数据库里需要存的字段定义这个model
至此最基本的概念和架构已经清楚了。