我正在尝试按照"Head First Rails“一书中的说明进行操作,在第50页上,它说要创建一个模型,但我无法使用rails命令创建模型。
当我在提示符下键入以下内容时: localhost:~ home$
rails generate model ad name:string description:text price:decimal seller_id:integer email:string img_url:string我明白了:
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /Users/home/.rvm/rubies/ruby-1.9.3-p125/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.
localhost:~ home$ 我使用的是Rails Ruby3.2.8和-v 1.9.3p125
发布于 2012-08-13 02:28:33
代码是正确的,但是您在错误的目录中。您必须在rails项目目录中运行这些命令。
从零开始的正常方法是:
$ rails new PROJECT_NAME
$ cd PROJECT_NAME
$ rails generate model ad \
name:string \
description:text \
price:decimal \
seller_id:integer \
email:string img_url:string发布于 2014-12-13 01:03:33
该错误显示您尚未创建rails项目,或者您不在rails项目目录中。
假设您正在处理我的应用程序项目。您必须在命令行上移动到该项目目录,然后生成模型。这里有一些你可以参考的步骤。
示例:假设您还没有创建Rails应用程序:
$> rails new myapp
$> cd myapp现在从命令行生成模型。
$> rails generate model your_model_name 发布于 2012-08-13 02:32:40
您需要首先创建新的rails应用程序。跑
rails new mebay
cd mebay
bundle install
rails generate model ...并尝试找到Rails3教程,因为2.1指南(http://guides.rubyonrails.org/getting_started.html)是一个很好的起点,所以有很多变化。
https://stackoverflow.com/questions/11924526
复制相似问题