I am new to Rails, so please forgive me if this is obvious.
我是Rails的新手,如果这很明显,请原谅我。
I am doing a lot of experimenting, creating to applications, testing features, etc. It got my first scaffolded app running great, but I wanted to create a second app to test a different feature.
我正在进行大量的实验,创建应用程序,测试功能等。它使我的第一个脚手架应用程序运行良好,但我想创建第二个应用程序来测试不同的功能。
I backed up a folder level on my computer, ran $ rails new taskmaster
(a test to-do list app). I ran the scaffolding for the Task
model, fired up the server via $ rails server
, and attempted to load http://localhost:3000
.
我在我的计算机上备份了一个文件夹级别,运行了$ rails new taskmaster(一个测试待办事项列表应用程序)。我为Task模型运行了脚手架,通过$ rails服务器启动了服务器,并尝试加载http:// localhost:3000。
But I got a routing error, saying it couldn't find the "members"
route. But members
was from my first Rails app! I thought by firing off $ rails server
in the taskmaster
directory, it would startup the server for that application.
但是我遇到了路由错误,说它无法找到“成员”路由。但成员来自我的第一个Rails应用程序!我想通过在taskmaster目录中触发$ rails服务器,它将启动该应用程序的服务器。
How do I tell the Rails server which application to serve up?
如何告诉Rails服务器提供哪个应用程序?
UPDATE
UPDATE
I just discovered that if I:
我刚发现如果我:
- Roll back to the fresh install of the first Rails app, before I created the Member scaffold
- 在创建Member脚手架之前,回滚到第一个Rails应用程序的全新安装
- Fire up the rails server via
$ rails server
in the application's root directory - 通过应用程序根目录中的$ rails服务器启动rails服务器
- Check
http://localhost:3000
- 检查http:// localhost:3000
It still attempts to go for the members
route, the one that no longer exists because I rolled back via git.
它仍然试图寻找成员路由,因为我通过git回滚而不再存在。
I'm guessing this means something in my /usr/local/
area, relating to my Ruby and Rails initial installs, is mainatining this info (my apps are setup in my Documents folder in my home dir).
我猜这意味着在我的/ usr / local / area中,与我的Ruby和Rails初始安装有关,正在维护这些信息(我的应用程序是在我家的目录中的Documents文件夹中设置的)。
I thought that Rails apps were essentially self contained apps inside the directory - you just needed a working Ruby install to get them going. Does the Rails server sit inside each app directory, or is the some overarching Rails server that accommodates all apps?
我认为Rails应用程序本质上是目录中的自包含应用程序 - 你只需要一个可用的Ruby安装来实现它们。 Rails服务器是否位于每个应用程序目录中,还是可以容纳所有应用程序的一些总体Rails服务器?
7 个解决方案
#1
46
I suspect the old server was still running and the new server failed to start. Try killing it first and then start it your new app.
我怀疑旧服务器仍在运行,新服务器无法启动。尝试先杀死它,然后启动它新的应用程序。
Alternatively, you could start the new server on a different port by using the -p
switch (e.g. rails server -p 3001
)
或者,您可以使用-p开关在不同的端口上启动新服务器(例如rails server -p 3001)
#2
21
You can run multiple instances of webrick server on localhost by assigning a different port number as:
您可以通过分配不同的端口号在localhost上运行webrick服务器的多个实例:
rails s -p 3007
But sometimes it may not work.
但有时可能无效。
I have a tip for you.You can try using this along with other options provided by webrick. Just try with providing any number as PID using -P
:
我有一个提示给你。你可以尝试使用这个以及webrick提供的其他选项。尝试使用-P提供任何数字作为PID:
rails s -p 3007 -P 42342
#3
9
You can't really tell the server which application to serve, but you can run a server for each application, and choose which one to load. If you want to run more than one server, you'll have to start them on different ports. The default port is 3000. To start a server on port 3001, run rails s -p 3001
on Rails 3 or script/server -p 3001
on Rails 2.
您无法真正告诉服务器要提供哪个应用程序,但您可以为每个应用程序运行服务器,并选择要加载的应用程序。如果要运行多个服务器,则必须在不同的端口上启动它们。默认端口为3000.要在端口3001上启动服务器,请在Rails 3上运行rails s -p 3001或在Rails 2上运行script / server -p 3001。
#4
2
To start rails server, run the command rails s
or rails server
The following options are valid
要启动rails服务器,请运行命令rails s或rails server以下选项有效
-p Port
-b Binding (ip address)
-c Config file (for custom rack configuration)
-d Daemonize server
-u Enable debugger
-e Change the environment (defaults to development)
-P Specify a PID file
So to run an instance to different port in local machine, use the following command
因此,要将实例运行到本地计算机中的不同端口,请使用以下命令
rails s -b 127.0.0.1 -p 8081
Note that you can remove "127.0.0.1" as "localhost" is the default host.
请注意,您可以删除“127.0.0.1”,因为“localhost”是默认主机。
For more information, check this reference http://guides.rubyonrails.org/command_line.html#rails-server
有关更多信息,请查看此参考http://guides.rubyonrails.org/command_line.html#rails-server
#5
2
In Rails 5 and Puma server, this is the way I could achieve this:
在Rails 5和Puma服务器中,这是我可以实现的方式:
With two terminals, run rails server
in each terminal specifying different Pid files and different ports:
使用两个终端,每个终端中的运行轨道服务器指定不同的Pid文件和不同的端口:
this way, I can simulate two domains for the same app on development
这样,我可以为开发中的同一个应用程序模拟两个域
#6
1
Thanks for all your help - turns out it was a rather strange occurrence. Somehow, my entire project folder got copied into the Trash. When I started the server, I was starting the server instance in the Trash copy, while the copy I rolled back and edited stay in the same place. Not sure how that happened (perhaps it relates to git, another tool I am just learning). In any case, thanks for all the help, sorry it was something so simple!
谢谢你的帮助 - 事实证明这是一个相当奇怪的事情。不知何故,我的整个项目文件夹被复制到废纸篓中。当我启动服务器时,我在垃圾箱副本中启动服务器实例,而我回滚并编辑的副本保留在同一个地方。不知道是怎么发生的(也许它与git有关,我正在学习的另一种工具)。在任何情况下,感谢所有的帮助,对不起它是如此简单!
#7
0
In the current version Rails 5.2.0 and Ruby 2.4.1p111, starting two instances of server for the same app is possible with multiple PIDs.
在当前版本的Rails 5.2.0和Ruby 2.4.1p111中,可以使用多个PID为同一个应用程序启动两个服务器实例。
$ rails s
=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.4 (ruby 2.4.1-p111), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
Now starting one more server on different port fails with pid issues.
现在,在不同端口上启动另一台服务器会出现pid问题。
$ rails s -p 3001
=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run `rails server -h` for more startup options
A server is already running. Check /Users/biju/app1/tmp/pids/server.pid.
Exiting
Below approach of starting server works to use multiple instances of application.
以下启动服务器的方法适用于使用多个应用程序实例。
$ rails s -p 3001 -P 321412
=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.4 (ruby 2.4.1-p111), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3001
Use Ctrl-C to stop
#1
46
I suspect the old server was still running and the new server failed to start. Try killing it first and then start it your new app.
我怀疑旧服务器仍在运行,新服务器无法启动。尝试先杀死它,然后启动它新的应用程序。
Alternatively, you could start the new server on a different port by using the -p
switch (e.g. rails server -p 3001
)
或者,您可以使用-p开关在不同的端口上启动新服务器(例如rails server -p 3001)
#2
21
You can run multiple instances of webrick server on localhost by assigning a different port number as:
您可以通过分配不同的端口号在localhost上运行webrick服务器的多个实例:
rails s -p 3007
But sometimes it may not work.
但有时可能无效。
I have a tip for you.You can try using this along with other options provided by webrick. Just try with providing any number as PID using -P
:
我有一个提示给你。你可以尝试使用这个以及webrick提供的其他选项。尝试使用-P提供任何数字作为PID:
rails s -p 3007 -P 42342
#3
9
You can't really tell the server which application to serve, but you can run a server for each application, and choose which one to load. If you want to run more than one server, you'll have to start them on different ports. The default port is 3000. To start a server on port 3001, run rails s -p 3001
on Rails 3 or script/server -p 3001
on Rails 2.
您无法真正告诉服务器要提供哪个应用程序,但您可以为每个应用程序运行服务器,并选择要加载的应用程序。如果要运行多个服务器,则必须在不同的端口上启动它们。默认端口为3000.要在端口3001上启动服务器,请在Rails 3上运行rails s -p 3001或在Rails 2上运行script / server -p 3001。
#4
2
To start rails server, run the command rails s
or rails server
The following options are valid
要启动rails服务器,请运行命令rails s或rails server以下选项有效
-p Port
-b Binding (ip address)
-c Config file (for custom rack configuration)
-d Daemonize server
-u Enable debugger
-e Change the environment (defaults to development)
-P Specify a PID file
So to run an instance to different port in local machine, use the following command
因此,要将实例运行到本地计算机中的不同端口,请使用以下命令
rails s -b 127.0.0.1 -p 8081
Note that you can remove "127.0.0.1" as "localhost" is the default host.
请注意,您可以删除“127.0.0.1”,因为“localhost”是默认主机。
For more information, check this reference http://guides.rubyonrails.org/command_line.html#rails-server
有关更多信息,请查看此参考http://guides.rubyonrails.org/command_line.html#rails-server
#5
2
In Rails 5 and Puma server, this is the way I could achieve this:
在Rails 5和Puma服务器中,这是我可以实现的方式:
With two terminals, run rails server
in each terminal specifying different Pid files and different ports:
使用两个终端,每个终端中的运行轨道服务器指定不同的Pid文件和不同的端口:
this way, I can simulate two domains for the same app on development
这样,我可以为开发中的同一个应用程序模拟两个域
#6
1
Thanks for all your help - turns out it was a rather strange occurrence. Somehow, my entire project folder got copied into the Trash. When I started the server, I was starting the server instance in the Trash copy, while the copy I rolled back and edited stay in the same place. Not sure how that happened (perhaps it relates to git, another tool I am just learning). In any case, thanks for all the help, sorry it was something so simple!
谢谢你的帮助 - 事实证明这是一个相当奇怪的事情。不知何故,我的整个项目文件夹被复制到废纸篓中。当我启动服务器时,我在垃圾箱副本中启动服务器实例,而我回滚并编辑的副本保留在同一个地方。不知道是怎么发生的(也许它与git有关,我正在学习的另一种工具)。在任何情况下,感谢所有的帮助,对不起它是如此简单!
#7
0
In the current version Rails 5.2.0 and Ruby 2.4.1p111, starting two instances of server for the same app is possible with multiple PIDs.
在当前版本的Rails 5.2.0和Ruby 2.4.1p111中,可以使用多个PID为同一个应用程序启动两个服务器实例。
$ rails s
=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.4 (ruby 2.4.1-p111), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
Now starting one more server on different port fails with pid issues.
现在,在不同端口上启动另一台服务器会出现pid问题。
$ rails s -p 3001
=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run `rails server -h` for more startup options
A server is already running. Check /Users/biju/app1/tmp/pids/server.pid.
Exiting
Below approach of starting server works to use multiple instances of application.
以下启动服务器的方法适用于使用多个应用程序实例。
$ rails s -p 3001 -P 321412
=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.4 (ruby 2.4.1-p111), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3001
Use Ctrl-C to stop