ruby on rails_Ruby on Rails解释

ruby on rails

Ruby on Rails is a server-side framework (gem) built on the Ruby language to make websites. It includes everything you need to build web applications and has a big community.

Ruby on Rails是基于Ruby语言构建的服务器端框架(gem),用于制作网站。 它包含构建Web应用程序所需的一切,并拥有一个庞大的社区。

Ruby on Rails is an opinionated framework, and emphasizes the use of convention over configuration (CoC), and don't repeat yourself (DRY) practices. Rails can best be described as a model-view-controller (MVC) framework, and provides sensible defaults and structures for rapid application development. Lately, Rails has integrated an API module to make the creation of web-services faster and easier.

Ruby on Rails是一个自以为是的框架,强调使用约定而不是配置(CoC),并且不要重复自己(DRY)的做法。 Rails可以最好地描述为模型视图控制器(MVC)框架,并为快速的应用程序开发提供合理的默认值和结构。 最近,Rails集成了一个API模块,以使创建Web服务更快,更轻松。

Ruby on Rails was created by David Heinemeir Hansson and is currently on it’s 6th version.

Ruby on Rails由David Heinemeir Hansson创建,目前是第6版。

如何安装Rails (How to install Rails)

Rails is downloaded in the same way as any other Ruby gem: with the gem install command. Before we download it, we’ll need to download Ruby. Afterwards we’re only 3 words away from starting with Ruby on Rails:

使用与其他Ruby gem相同的方式下载Rails:使用gem install命令。 在下载它之前,我们需要下载Ruby 。 然后,距离Ruby on Rails仅有3个词:

$ gem install rails

Rails ships with sqlite3 as the default database, which is a simple file on disk. You need to install MySQL or PostgreSQL if you want to use something more robust.

Rails附带sqlite3作为默认数据库,它是磁盘上的一个简单文件。 如果要使用更强大的功能,则需要安装MySQL或PostgreSQL。

如何创建Rails应用程序 (How to create a Rails application)

  1. After you install Ruby on Rails, it’s very simple to create a brand new application, we’ll just need 3 more words:

    在安装Ruby on Rails之后,创建全新的应用程序非常简单,我们只需要再输入3个字即可:
$ rails new your_application_name

2. If you want to use MySQL:

2.如果要使用MySQL:

$ rails new <application_name> -d mysql

3. If you want to use Postgres:

3.如果要使用Postgres:

$ rails new <application_name> -d postgresql

4. This command will create a folder with the yourapplicationname you informed in the last command. Next step is to go to the new directory you’ve just created:

4.此命令将创建一个文件夹,其中包含在上一个命令中告知应用程序名称 。 下一步是转到您刚刚创建的新目录:

$ cd your_application_name

5. Get the necessary gems and software packages before running your application:

5.在运行应用程序之前,获取必要的gem和软件包:

$ bundle install

6. To run the rails server and see if everything went accordingly is also fast:

6.运行rails服务器并查看一切是否也很快:

$ rails server

It couldn’t be anymore simple! Well, this isn’t actually 100% true, we could make it even smaller by reducing the rails server command to:

它再简单不过了! 嗯,这实际上不是100%正确,我们可以通过将rails server命令减少为以下内容来使其更小:

$ rails s

7. Now with your preferred browser, go to http://localhost:3000 and you’ll see: “Yay! You’re on Rails!”

7.现在,使用您喜欢的浏览器,转到http://localhost:3000 ,您将看到:“是的! 你在铁轨上!”

创建Rails应用程序的替代方法 (Alternative method for creating a Rails application)

  1. Create a new directory:

    创建一个新目录:
$ mkdir <application_name>

2. Go into the new directory:

2.进入新目录:

$ cd <application_name>

3. Create the Rails application using the Unix dot notation. This results in assigning the name of the directory to the new application:

3.使用Unix点表示法创建Rails应用程序。 这导致将目录名称分配给新应用程序:

$ rails new .

4. Start exploring the framework of the application you just created. To see a useful table of the folder structure, check out Getting Started with Rails.

4.开始探索您刚刚创建的应用程序的框架。 要查看文件夹结构的有用表格,请查看Rails入门

约定优于配置 (Convention over Configuration)

Convention over Configuration means a developer only needs to specify unconventional aspects of the application. For example, if there is a class Sale in the model, the corresponding table in the database is called sales by default. It is only if one deviates from this convention, such as calling the table “products sold”, that the developer needs to write code regarding these names. Generally, Ruby on Rails conventions lead to less code and less repetition.

约定优于配置意味着开发人员只需指定应用程序的非常规方面。 例如,如果模型中有一个Sale类,则默认情况下数据库中的对应表称为sales 。 只有当人们偏离此约定(例如将表称为“所售产品”)时,开发人员才需要编写有关这些名称的代码。 通常,Ruby on Rails约定导致更少的代码和更少的重复。

什么是MVC? (What is MVC?)

Model (Active record) contains the business logic and interacts with the database. Views (Action views) all of the HTML files and structure. Controller (Action controller) interacts with the views and model to direct the actions of the application.

模型(活动记录)包含业务逻辑并与数据库进行交互。 查看(动作视图)所有HTML文件和结构。 控制器(动作控制器)与视图和模型进行交互以指导应用程序的动作。

干-不要重复自己 (DRY - Don’t Repeat Yourself)

Don’t repeat yourself means that information is located in a single, unambiguous place. For example, using the ActiveRecord module of Rails, the developer does not need to specify database column names in class definitions. Instead, Ruby on Rails can retrieve this information from the database based on the class name.

不要重复自己,这意味着信息位于一个明确的位置。 例如,使用Rails的ActiveRecord模块,开发人员无需在类定义中指定数据库列名称。 相反,Ruby on Rails可以基于类名从数据库检索此信息。

Ruby on Rails是开源的 (Ruby on Rails is open source)

Not only is it free to use, you can also help make it better. More than 4,500 people have already contributed code to Rails. It’s easier than you think to become one of them.

它不仅可以免费使用,还可以帮助使其变得更好。 已有4,500多人向Rails提供了代码。 成为您的一员比想象的要容易。

翻译自: https://www.freecodecamp.org/news/ruby-on-rails-explained/

ruby on rails

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值