ruby-on-rails_Ruby on Rails

贺景山
2023-12-01

ruby-on-rails

Ruby on Rails (Ruby on Rails)

Ruby on Rails is a free framework that promises to increase speed and ease in website development-oriented database (database-driven web sites), since it is possible to create applications based on predefined structures. Often referred to as Rails or RoR, Ruby on Rails is an open source project written in Ruby programming language. Applications created using the Rails framework are developed based on the design pattern MVC (Model-View-Controller).

Ruby on Rails是一个免费框架,它有望提高面向网站开发的数据库(数据库驱动的网站)的速度和便利性,因为可以基于预定义的结构创建应用程序。 Ruby on Rails通常被称为Rails或RoR,是一个用Ruby编程语言编写的开源项目。 使用Rails框架创建的应用程序是基于设计模式MVC(模型-视图-控制器)开发的。

Ruby on Rails was extracted from a David Heinemeier Hansson of one of its projects, the project manager Basecamp. It was released to the public for the first time in July 2004.

Ruby on Rails摘自其项目之一David Heinemeier Hansson的项目经理Basecamp。 它于2004年7月首次向公众发布。

Ruby on Rails组件 (Ruby on Rails Components )

Rails is a “meta-framework”, since it is a junction of five frameworks:

Rails是“元框架”,因为它是五个框架的结合:

Active Record

活动记录

Active Record is a layer of mapping object-relational (object-relational mapping layer), responsible for interoperability between application and database and data abstraction.

Active Record是映射对象关系的层(对象关系映射层),负责应用程序与数据库之间的互操作性以及数据抽象。

Action Pack

行动包

Understands the Action View (generation of user viewing as HTML, XML, JavaScript, etc.) and the Action Controller (control the flow of business).

了解操作视图(以HTML,XML,JavaScript等形式生成用户视图)和操作控制器(控制业务流程)。

Action Mailer

动作邮件

The Action Mailer is a framework responsible for the delivery service and even receive e-mails. It is relatively small and simple, but powerful and able to perform various operations with calls only mail delivery.

Action Mailer是负责传递服务甚至接收电子邮件的框架。 它相对较小且简单,但是功能强大并且仅通过邮件传递就可以执行各种操作。

Active Support

积极支持

Active Support is a collection of several useful classes and extensions to standard libraries, which were considered useful for applications in Ruby on Rails.

活动支持是几个有用的类和标准库扩展的集合,这些类和扩展被认为对Ruby on Rails中的应用有用。

Action WebServices

动作Web服务

Provides a way to publish interoperable APIs with Rails without the need to spend time in protocol specifications. Implements WSDL and SOAP.

提供了一种发布与Rails互操作的API的方法,而无需花费时间在协议规范上。 实现WSDL和SOAP。

The Action Web Service is no longer present in version 2.0 on Rails, since that is turning to the use of the REST model. Still, even those interested in using it, you can do so by installing a plugin.

在Rails的2.0版中不再提供Action Web Service,因为这已转向使用REST模型。 尽管如此,即使是有兴趣使用它的人,也可以通过安装插件来实现。

Development Time

开发时间

Ruby on Rails follows two concepts aimed at increasing developer productivity: DRY and Convention over Configuration. These methods are implemented across the rails, but may be more noticeable in “packages” Active Record (ORM, Object Relational Mapper) and Action Pack (MVC)

Ruby on Rails遵循两个旨在提高开发人员生产力的概念:DRY和Convention on Configuration。 这些方法是跨导轨实现的,但在“包” Active Record(ORM,对象关系映射器)和Action Pack(MVC)中可能更引人注意。

DRY

干燥

DRY (Do not Repeat Yourself, Do not repeat yourself) is the concept behind the technique of defining names, properties and codes in one place and reuse this information to others.

DRY(不要重复自己,不要重复自己)是在一个地方定义名称,属性和代码并将此信息重用于其他地方的技术背后的概念。

For example, instead of having a People table and a class Person with a property, a method “accessor (getter) and a” modifier “(setter) for each field in the table, it has been only in the database. Properties and methods needed are “injected” in the class through features of Ruby.

例如,表中的每个字段都没有一个People表和一个具有属性的Person类,而是为表中的每个字段提供了一种方法“ accessor(getter)和a修饰符”(setter),而仅存在于数据库中。 通过Ruby的功能将所需的属性和方法“注入”到类中。

Thus, this saves time, since it is not necessary to change the table, the “bean”, the “form bean”, the “home site”, the “home”, the “session”, … Changing only the database, everything is based on this information is updated automatically.

因此,由于无需更改表,“ bean”,“ form bean”,“ home site”,“ home”,“ session”,……,因此无需更改表,从而节省了时间。基于此信息将自动更新。

Convention over configuration

约定优于配置

In most cases, we use conventions in the day-to-day programming in general to facilitate understanding and maintenance by other developers. Knowing this, and knowing that the time spent to set up frameworks for XML in some other languages is extremely high, it was decided to adopt the concept.

在大多数情况下,我们通常在日常编程中使用约定,以促进其他开发人员的理解和维护。 知道这一点,并且知道花费一些时间来建立其他语言的XML框架之后,便决定采用该概念。

He basically says that one must assume default values where there is a convention. If the developer wants, you can override this convention with the necessary amount. For example, a User class can have their data stored in the Customer table. Following convention, would be in the Users table. Thus, the development time drops further.

他基本上说,在有约定的情况下,必须假定默认值。 如果开发人员需要,可以用必要的数量覆盖此约定。 例如,一个User类可以将其数据存储在Customer表中。 按照约定,将在Users表中。 因此,开发时间进一步减少。

Ruby on Rails –可扩展性 (Ruby on Rails – Scalability )

Most sites do not need sophisticated schemes to scale, just a few accelerators. In smaller sites, or normal, a default web server can handle a good amount of cargo, especially if you use FastCGI, Mongrel or LightTPD, which are necessary to obtain an acceptable speed of opening the page. Comparing an application with FastCGI and FastCGI without (running straight as Ruby CGI), the difference is noticeable in any application. The processing of the code (not counting download time) CGI occurs in at least 10 seconds even on servers Quad Core, while in FastCGI performance is remarkable: in a maximum of 1 second page is processed, such as which web languages PHP.

大多数站点不需要复杂的方案即可扩展,仅需几个加速器即可。 在较小的站点或正常的站点中,默认的Web服务器可以处理大量的货物,尤其是如果您使用FastCGI,Mongrel或LightTPD,这对于获得可接受的打开页面速度是必需的。 将应用程序与不带FastCGI和FastCGI的应用程序进行比较(直接运行为Ruby CGI),在任何应用程序中差异都非常明显。 即使在服务器Quad Core上,代码的CGI处理(不计算下载时间)也至少在10秒内发生,而在FastCGI中,性能却是惊人的:最多处理1秒的页面,例如使用哪种Web语言PHP。

There are cases of websites done in Rails that supported 5 million hits a month, or approximately 115 per minute, a performance considered sufficient for 90% of current applications. In these sites, a frequent question is about the scalability of applications written in Rails. Unlike other technologies, you do not need a specific code that the system is prepared to “escalate”. When necessary we can adopt one of the tactics available to scale on Rails. Notably, the only problem of scalability is to maintain sessions between servers. Therefore, the output most obvious is to keep these sessions on NFS volumes, accessible by all application servers. Another tactic is to use session caching directly to the database. A third would save the session in a cookie on the user’s machine. As you can see, a Rails application is born with all the support necessary to grow painlessly.

在Rails中完成的网站案例中,每月支持500万次点击,或每分钟大约115次,这种性能足以满足当前90%的应用程序的需求。 在这些站点中,经常遇到的问题是有关用Rails编写的应用程序的可伸缩性。 与其他技术不同,您不需要系统准备“升级”的特定代码。 必要时,我们可以采用一种可在Rails上扩展的策略。 值得注意的是,可伸缩性的唯一问题是维护服务器之间的会话。 因此,最明显的输出是将这些会话保留在所有应用程序服务器都可以访问的NFS卷上。 另一种策略是直接使用会话缓存到数据库。 三分之一将会话保存在用户计算机上的cookie中。 如您所见,Rails应用程序天生具有无痛成长所需的所有支持。

Study: From Wikipedia, the free encyclopedia. The text is available under the Creative Commons.

研究:来自维基百科,免费的百科全书。 该文本可在“ 知识共享”下找到

翻译自: https://www.eukhost.com/blog/webhosting/ruby-on-rails-2/

ruby-on-rails

 类似资料: