繁体   English   中英

导轨 g model 或导轨 g 脚手架不会创建 model

[英]rails g model or rails g scaffold doesn't create model

我开始使用 Ruby 并使用简单的应用程序来获得基础知识。

我使用 --skip-active-record 标志创建应用程序。 现在我需要一个 model 和两个rails g model Articles title:string text:string or rails g scaffold Articles title:string text:string

环境:

  • 赢 7 x64
  • ruby 2.7.1p83(2020-03-31 修订版 a0c7c23c9c)[x64-mingw32]
  • 导轨 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'

您对问题出在哪里有想法吗?

我理解你已经使用了--skip-active-record ,你是在通知应用程序你不会使用模型。 因此,它实际上跳过了 model 文件夹。 我不确定您是否 100% 确定您的动机。 但如果您想在这种情况下启用它,您可以执行以下操作。

1. Add database related gem in Gemfile ex: gem 'mysql2'
2. In config/application.rb uncomment the line require "active_record/railtie"
3. Add database.yml

    

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM