【问题标题】:Deployed ruby on rails on shared hosting - routing issue在共享主机上部署 ruby​​ on rails - 路由问题
【发布时间】:2012-12-20 05:45:09
【问题描述】:

我是 Rails 新手。我正在努力让一个简单的 helloworld rails 应用程序(无数据库)在共享主机上工作。

开发日志

Processing ApplicationController#index (for 122.61.170.222 at 2012-12-17 17:46:09) [GET]

ActionController::RoutingError (No route matches "/Say/hello" with {:method=>:get}):


Rendering rescues/layout (not_found)

我的 Rails 设置:http://scifiwear.com/rails_setup.png

rails setup http://scifiwear.com/rails_setup.png

我的子域设置:http://scifiwear.com/subdomain.png

subdomain setup http://scifiwear.com/subdomain.png

服务器版本:

Ruby 版本:1.8.7 宝石版本:1.8.16 Rails 是 2.3.14

我配置 helloWorld 应用程序的步骤:

  1. 使用网络表单http://scifiwear.com/rails_setup.png创建的应用程序

  2. cd myapp14

  3. ruby 脚本/生成控制器说再见

  4. http://myapp14.scifiwear.com/快乐!

5 http://myapp14.scifiwear.com/say/hello 不开心!

mongrel.log:

Mon Dec 17 17:46:09 -0600 2012: Error calling Dispatcher.dispatch #<NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.split>
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/cgi_process.rb:52:in `dispatch_cgi'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/dispatcher.rb:101:in `dispatch_cgi'
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/dispatcher.rb:27:in `dispatch'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:76:in `process'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:74:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:74:in `process'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:159:in `process_client'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:158:in `each'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:158:in `process_client'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:285:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:285:in `initialize'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:285:in `new'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:285:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:268:in `initialize'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:268:in `new'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:268:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/configurator.rb:282:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/configurator.rb:281:in `each'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/configurator.rb:281:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:128:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/command.rb:212:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281
/usr/bin/mongrel_rails:19:in `load'
/usr/bin/mongrel_rails:19

我的 routes.rb 的最后 4 行:(未改动)

# consider removing or commenting them out if you're using named routes and resources.

map.connect ':controller/:action/:id'

map.connect ':controller/:action/:id.:format'

end

任何建议都非常感谢。

【问题讨论】:

  • 你能发布你的整个 routes.rb 和有问题的控制器操作吗?请查看guides.rubyonrails.org/routing.html>
  • routes.rb 中的所有内容都被注释掉了,除了上面看到的第一行和最后 3 行。这是一个默认的 routes.rb。

标签: ruby-on-rails shared-hosting


【解决方案1】:

尝试上一个问题的答案:Problems running Ruby on Rails apps on shared hosted server;在这种情况下,它们可能会有所帮助。

我尝试使用rails 2.3.14ruby 1.8.7-p371 在本地重现相同的错误;没有收到错误信息。路由文件与您拥有的类似。

日志跟踪如下:

=> Booting Mongrel
=> Rails 2.3.14 application starting on http://0.0.0.0:3000
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /Users/hallelujah/.rvm/gems/ruby-1.8.7-p371@hallelujah/gems/rails-2.3.14/lib/rails/gem_dependency.rb:21.
NOTE: Gem::SourceIndex#initialize is deprecated with no replacement. It will be removed on or after 2011-11-01.
Gem::SourceIndex#initialize called from /Users/hallelujah/.rvm/gems/ruby-1.8.7-p371@hallelujah/gems/rails-2.3.14/lib/rails/vendor_gem_source_index.rb:100.
=> Call with -d to detach
=> Ctrl-C to shutdown server


Processing SayController#hello (for 127.0.0.1 at 2012-12-20 15:52:23) [GET]
Rendering say/hello
Completed in 35ms (View: 34, DB: 0) | 200 OK [http://localhost/say/hello]

鉴于此托管服务器上的 ruby​​ 和 rails 版本非常旧,您可能很难就安装时遇到的问题获得帮助。而且您在学习这些概念时也会遇到困难。

我的建议是让您改用最新版本的 ruby​​ 和 rails(并了解使用 rails 进行 Web 开发的最佳实践),遵循 Michael Hartl 的优秀且免费提供的在线书籍:Ruby on Rails Tutorial

【讨论】:

  • Prakash 你试图用相同的版本号重现错误给我留下了深刻的印象!我觉得你的建议很好。我现在正在联系我的托管公司,看看他们是否可以帮助我解决这个问题。如果没有,我将使用最新版本的专用 Rails 主机。看好你。谢谢。 :)
猜你喜欢
  • 1970-01-01
  • 2010-11-30
  • 2023-03-24
  • 2018-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多