简体   繁体   English

Ruby on Rails执行

[英]ruby on rails execution

I am new to Ruby on Rails. 我是Ruby on Rails的新手。 I am trying my best to learn it through the book Agile Web Development Using Rails . 我正在努力通过《 使用Rails进行敏捷Web开发》这本书来学习它。 I got stuck trying to understand the concepts behind the execution. 我被困于试图理解执行背后的概念。

I created a new project using rails_apps> rails demo . 我使用rails_apps> rails demo创建了一个新项目。 The book asked me to create a controller called Say (please note the capital "S") and the following happened: 这本书要求我创建一个名为Say的控制器(请注意大写的“ S”),然后发生了以下情况:

  1. there was a folder by the name say (please note the lowercase "s") inside a folder called "views" 在名为“ views”的文件夹中有一个名字说(请注意小写的“ s”)的文件夹
  2. there was a controller file :say_controller". 有一个控制器文件:say_controller”。

I then made a request through http://localhost/say/hello . 然后,我通过http://localhost/say/hello发出了一个请求。 I am really confused by the fact that, my project name demo is nowhere in the request. 我对项目名称演示不在请求中这一事实感到非常困惑。 What happens if I create another controller in, say, another project and make the same request? 如果我在另一个项目中创建另一个控制器并发出相同的请求,会发生什么情况?

And why is that say has a lowercase s in the request instead of capital S? 为什么说请求中的小写字母s代替大写字母S? What's happening behind the curtains here? 幕后发生了什么事?

When you run the command rails server it is launching a process that is only for the specific application. 当您运行命令rails server它将启动仅适用于特定应用程序的进程。 It sees the request from the browser for that application and serves the appropriate content. 它查看来自浏览器的对该应用程序的请求并提供适当的内容。

If you made another application, you would not be able to run it on the same port at the same time as the original application. 如果创建了另一个应用程序,则将无法与原始应用程序同时在同一端口上运行它。 You would need to run rails server -p NEW_PORT where NEW_PORT is different from the already running rails application. 您将需要运行rails server -p NEW_PORT ,其中NEW_PORT与已经运行的Rails应用程序不同。 Then you would be able to access the application from http://localhost:NEW_PORT 然后,您将可以从http:// localhost:NEW_PORT访问该应用程序

The multiple servers allow you to have the same controllers in different applications, because they are completely separate instances now. 多个服务器使您可以在不同的应用程序中使用相同的控制器,因为它们现在是完全独立的实例。

Taking your questions one by one: 一一解答您的问题:

The "name" of your app (the parameter you provide to the rails script) is not used anywhere except for the name of the main directory. 应用程序的“名称”(您提供给rails脚本的参数)除了主目录的名称外,其他任何地方都不会使用。 I find this provides freedom to not be locked in to the chosen name. 我发现这提供了不被锁定到所选名称的自由。

Another controller in another project will be completely independent. 另一个项目中的另一个控制器将完全独立。 The two projects will run at different ports (when using the built-in webserver) or on different paths (when using another webserver like Apache.) 这两个项目将在不同的端口上运行(使用内置Web服务器时)或在不同的路径上运行(使用其他Web服务器(如Apache)时)。

Capitalized (and "camel cased") vs. uncapitalized names are important in Rails, and are simply dictated by convention. 在Rails中,大写(和“驼峰大小写”)与未大写的名称很重要,并且仅由惯例规定。 Here's a post with some examples. 这里有一些例子。 http://itsignals.cascadia.com.au/?p=7 http://itsignals.cascadia.com.au/?p=7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM