【发布时间】:2020-07-30 09:37:04
【问题描述】:
我正在开始使用 Ruby,并正在开发简单的应用程序以获取基础知识。
我使用 --skip-active-record 标志创建应用程序。现在我需要一个模型,rails g model Articles title:string text:string or rails g scaffold Articles title:string text:string 都不会生成模型(注意:scaffold 命令会创建除模型之外的所有内容)。
环境:
- Win 7 x64
- ruby 2.7.1p83(2020-03-31 修订版 a0c7c23c9c)[x64-mingw32]
- Rails 6.0.3.2
宝石文件
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.2'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem 'rack-cors'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'ruby_cowsay'
gem 'jbuilder'
gem 'sqlite3', git: "https://github.com/larskanis/sqlite3-ruby", branch: "add-gemspec"
gem 'activerecord', '~> 6.0', '>= 6.0.3.2'
您对问题出在哪里有想法吗?
【问题讨论】:
-
如果您不告诉我们错误是什么,我们将无法帮助您:) 请在尝试您的命令后粘贴您的终端输出
-
为空,没有错误。第一个命令执行并打印(并创建)任何内容。 Scaffold 命令创建(并在控制台中打印)除模型之外的所有预期内容
-
如果在查看问题后您没有发现任何问题,我想请教一下,请按照我的步骤创建模型。如果创建了模型,请分享您的 gemfile 和其他环境条件
-
有点奇怪:你的
rails g model通常会创建迁移来创建表,模型总是从ActiveRecord::Base派生的,因为你没有使用活动记录,rails 是如何知道你想要的存储/创建列和模型?您对此有何期待? -
我的意图是向现有应用程序添加活动记录,我更喜欢使用 sqlite3 作为存储。您可能会注意到上面 gemfile 中的 activerecord gem。它应该回答评论中的第一个问题。我对上述命令的期望是创建一个模型。
标签: ruby-on-rails ruby rails-activerecord