【问题标题】:Can not acces localhost:3000 ruby on rails ubuntu无法访问 localhost:3000 ruby​​ on rails ubuntu
【发布时间】:2015-04-23 01:42:12
【问题描述】:

我一直在尝试通过运行rails srails server 命令在我的Rails 中访问或至少显示我的服务器,但它不起作用:

起初它告诉我必须安装新的 gem 并运行命令 bundle install 来升级它们,我做到了。它“正确”地安装了所有东西。

现在,我只是获得了一些使用帮助而不是 Rails(例如我可以使用的命令)。我以为 Rails 已经出局了,但我运行了命令rails new myApp,它确实为我创建了一个,并且包安装正常。我只想启动我的应用程序并尝试localhost:port,然后打开我的应用程序。

当我尝试生成某些东西时也会发生同样的情况,例如rails g model OneModel(或generate 而不是g)以及我想要生成的任何东西。它似乎不理解我的命令。

我是 ubuntu 的新手,而且对 Rails 和 ruby​​ 来说还很陌生。如果你能帮助我,我会很高兴。这是我得到的输出:

agustin@agustin:~/Agustin/myapp$ rails s
Usage:
  rails new APP_PATH [options]

Options:
  -r, [--ruby=PATH]              # Path to the Ruby binary of your choice
                                 # Default: /usr/bin/ruby
  -b, [--builder=BUILDER]        # Path to a application builder (can be a filesystem path or URL)
  -m, [--template=TEMPLATE]      # Path to an application template (can be a filesystem path or URL)
      [--skip-gemfile]           # Don't create a Gemfile
      [--skip-bundle]            # Don't run bundle install
  -G, [--skip-git]               # Skip Git ignores and keeps
  -O, [--skip-active-record]     # Skip Active Record files
  -S, [--skip-sprockets]         # Skip Sprockets files
  -d, [--database=DATABASE]      # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
                                 # Default: sqlite3
  -j, [--javascript=JAVASCRIPT]  # Preconfigure for selected JavaScript library
                                 # Default: jquery
  -J, [--skip-javascript]        # Skip JavaScript files
      [--dev]                    # Setup the application with Gemfile pointing to your Rails checkout
      [--edge]                   # Setup the application with Gemfile pointing to Rails repository
  -T, [--skip-test-unit]         # Skip Test::Unit files
      [--old-style-hash]         # Force using old style hash (:foo => 'bar') on Ruby >= 1.9

Runtime options:
  -f, [--force]    # Overwrite files that already exist
  -p, [--pretend]  # Run but do not make any changes
  -q, [--quiet]    # Suppress status output
  -s, [--skip]     # Skip files that already exist

Rails options:
  -h, [--help]     # Show this help message and quit
  -v, [--version]  # Show Rails version number and quit

Description:
    The 'rails new' command creates a new Rails application with a default
    directory structure and configuration at the path you specify.

    You can specify extra command-line arguments to be used every time
    'rails new' runs in the .railsrc configuration file in your home directory.

    Note that the arguments specified in the .railsrc file don't affect the
    defaults values shown above in this help message.

Example:
    rails new ~/Code/Ruby/weblog

    This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
    See the README in the newly created application to get going.
agustin@agustin:~/Agustin/myapp$ 

【问题讨论】:

  • 您是在尝试运行现有的 Rails 应用程序还是创建一个新的应用程序并运行它?
  • “我以为 Rails 已经出局了”是什么意思?
  • 我的意思是我认为它停止工作了。我已经创建了一个新应用程序,我正试图让它在我的端口 3000 中由我的浏览器运行,我知道它的默认值。除了 new i type 之外的任何命令都不起作用,并抛出我......
  • @das-g 我真的不知道这有什么问题

标签: ruby-on-rails ruby ubuntu localhost


【解决方案1】:

你必须从项目根目录运行rails s

例如,如果您创建一个rails 应用程序,比如rails new my_app,它将在当前目录中创建一个框架应用程序my_app。现在你必须 cd 到那个目录来启动服务器

【讨论】:

  • 我做了,你可以在 myapp 文件夹中看到它
  • @Agustin - 请输入ls 并分享结果。
  • 在任何文件夹或我的应用程序文件夹中
  • @BroiSatse 我想你想要斜体字的,这是我的应用程序文件夹。粗体是通用的,但我认为你不需要这个
  • @Agustin 在运行rails s 时,您是否在myapp 目录中?它只能在那里工作。