我正在尝试在RoR中创建一个非常简单的Hello,World程序,但当我去查看网址http://localhost:3000/say/hello
时,我收到错误消息No route matches: "say/hello"
当我启动rails服务器时,我收到了这条消息,其中散布着警告:
=> Booting WEBrick
=> Rails 3.0.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-06-20 20:02:44] INFO WEBrick 1.3.1
[2011-06-20 20:02:44] INFO ruby 1.9.2 (2011-02-18) [i686-linux]
[2011-06-20 20:02:44] WARN TCPServer Error: Address already in use - bind(2)
Exiting
/home/eyedea/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/utils.rb:73:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE)
from /home/eyedea/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/utils.rb:73:in `new'
from /home/eyedea/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/utils.rb:73:in `block in create_listeners'
from /home/eyedea/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/utils.rb:70:in `each'
from /home/eyedea/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/utils.rb:70:in `create_listeners'
from /home/eyedea/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/server.rb:74:in `listen'
from /home/eyedea/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/server.rb:62:in `initialize'
from /home/eyedea/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:24:in `initialize'
from /home/eyedea/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/handler/webrick.rb:10:in `new'
from /home/eyedea/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/handler/webrick.rb:10:in `run'
from /home/eyedea/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/server.rb:217:in `start'
from /home/eyedea/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands/server.rb:65:in `start'
from /home/eyedea/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:30:in `block in <top (required)>'
from /home/eyedea/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:27:in `tap'
from /home/eyedea/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
我开始:rails生成控制器说再见 列出路线得到“说/你好”
另外:我遇到的问题可能与此有关。当我在其中一个明确列为现有的文件中写一些基本的html时,我得到了这个:
我写这个:
~/work/demo$ /app/views/say/hello.html.erb
获取此错误消息:
bash: /app/views/say/hello.html.erb: No such file or directory
这里发生了什么?我直接从使用Rails的Agile Development获得这些指令,这很简单。我不明白发生了什么。
答案 0 :(得分:1)
您在rails启动时遇到的错误表明您的计算机上已经有一台服务器在端口3000上运行(显然服务器不知道“说/你好”路由)。关闭那个,然后再试一次。
答案 1 :(得分:1)
[2011-06-20 20:02:44] WARN TCPServer Error: Address already in use - bind(2)
您已经在服务器应该运行的端口上运行服务器(或其他东西)。因此,您认为正在运行的代码(您说有相关路线)实际上没有运行。一旦你关闭了另一个进程(可能是以前运行的rails服务器?),你可以启动正确的进程并确保它实际上有这条路由。
答案 2 :(得分:0)
第二个错误是因为从bash路径/
进入根目录。尝试:
cat app/views/say/hello.html.erb
答案 3 :(得分:0)
我遇到了类似的问题。在我的情况下,$ rails server命令后,我无法在终端本身使用ctrl-C关闭服务器。当我在终端中按ctrl-C时没有任何反应。
当我在另一个终端上重新打开项目并再次运行时,我收到以下消息:
System-Product-Name:〜/ testapp $ rails s
=&GT;启动WEBrick
=&GT; Rails 3.1.0.rc4应用程序从http://0.0.0.0:3000开始开发
=&GT;用-d调用分离
=&GT; Ctrl-C关闭服务器
[2011-06-30 16:41:23] INFO WEBrick 1.3.1
[2011-06-30 16:41:23] INFO ruby 1.9.2(2011-02-18)[x86_64-linux]
[2011-06-30 16:41:23] WARN TCPServer错误:地址已在使用中 - bind(2)
退出
/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/utils.rb:73:in initialize': Address already in use - bind(2) (Errno::EADDRINUSE)
ls.rb:73:in
new'
来自bubble / .rvm / rubies / ruby-1.9.2-p180 / lib / ruby / 1.9.1 / webrick / utils.rb:73:in block in create_listeners'
from bubble/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/utils.rb:70:in
each'
来自bubble / .rvm / rubies / ruby-1.9.2-p180 / lib / ruby / 1.9.1 / webrick / utils.rb:70:in create_listeners'
from bubble/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/server.rb:74:in
listen'
来自bubble / .rvm / rubies / ruby-1.9.2-p180 / lib / ruby / 1.9.1 / webrick / server.rb:62:in initialize'
from bubble/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:24:in
initialize'
来自bubble /.rvm/gems/ruby-1.9.2-p180@rails31/gems/rack-1.3.0/lib/rack/handler/webrick.rb:10:in new'
from bubble/.rvm/gems/ruby-1.9.2-p180@rails31/gems/rack-1.3.0/lib/rack/handler/webrick.rb:10:in
run'
来自bubble /.rvm/gems/ruby-1.9.2-p180@rails31/gems/rack-1.3.0/lib/rack/server.rb:265:in start'
from bubble/.rvm/gems/ruby-1.9.2-p180@rails31/gems/railties-3.1.0.rc4/lib/rails/commands/server.rb:70:in
start'
来自bubble /.rvm/gems/ruby-1.9.2-p180@rails31/gems/railties-3.1.0.rc4/lib/rails/commands.rb:54:in block in <top (required)>'
from bubble/.rvm/gems/ruby-1.9.2-p180@rails31/gems/railties-3.1.0.rc4/lib/rails/commands.rb:49:in
点击'
来自bubble /.rvm/gems/ruby-1.9.2-p180@rails31/gems/railties-3.1.0.rc4/lib/rails/commands.rb:49:in <top (required)>'
from script/rails:6:in
require'
来自script / rails:6:in''
本质上我必须每次都从系统监视器中删除进程。这可以治愈吗?
答案 4 :(得分:0)
在Mac上,在终端中键入以下内容:
lsof | grep IPv4
或
我认为在Linux中 lsof|grep 3000
。
找到以'ruby'开头的lione并记下旁边的数字。
假设数字是1234.在终端输入以下内容:
kill -9 1234
你应该是对的。记得用control-c退出WEBrick!