简体   繁体   English

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

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

I am getting started with Ruby and working on simple app to get the basics.我开始使用 Ruby 并使用简单的应用程序来获得基础知识。

I create the app with --skip-active-record flag.我使用 --skip-active-record 标志创建应用程序。 Now I need a model and neither rails g model Articles title:string text:string or rails g scaffold Articles title:string text:string doesn't generate the model (note: scaffold command creates everything except model).现在我需要一个 model 和两个rails g model Articles title:string text:string or rails g scaffold Articles title:string text:string

Environment:环境:

  • Win 7 x64赢 7 x64
  • ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c)[x64-mingw32] ruby 2.7.1p83(2020-03-31 修订版 a0c7c23c9c)[x64-mingw32]
  • Rails 6.0.3.2导轨 6.0.3.2

Gemfile宝石文件

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'

Do you have a thoughts on where is the issue?您对问题出在哪里有想法吗?

what I understand as you have used --skip-active-record by this you are informing the application that you are not going to use models.我理解你已经使用了--skip-active-record ,你是在通知应用程序你不会使用模型。 For that reason it is actually skipping the model folder.因此,它实际上跳过了 model 文件夹。 I am not sure about your 100% sure about your motive here.我不确定您是否 100% 确定您的动机。 but if you want to enable it in that case you can do the following.但如果您想在这种情况下启用它,您可以执行以下操作。

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