创建一个没有数据库的rails项目

方法一:

创建的时候,跳过创建数据库,跳过bundle等等。。什么都没有,自己写项目的时候,自己再做,一个真正干干净净,从零开始的项目。

rails new --skip-active-record --skip-bundle --skip-yarn --skip-spring --skip-listen 【项目名】

记得改变Gemfile,bundle install ,  Gemfile 文件举个例子:

source 'https://gems.ruby-china.com/'

gem 'rails', '~> 5.1.4'
gem 'puma', '~> 3.7'

gem 'coffee-rails', '~> 4.2'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'

gem 'jquery-rails', '~> 4.3.3'
gem 'bootstrap', '~> 4.1.1'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'haml', '~> 5.0.4'


group :development do
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'

  gem 'pry-rails', '~> 0.3.4'
  gem 'capistrano', '~> 3.9'
  gem 'capistrano-rails', "~> 1.3.0"
  gem 'capistrano-rvm', "~> 0.1.2"
  gem 'capistrano3-puma', "~> 3.1.1"
end

 

方法二:

创建一个应用程序,用   -0   跳过创建数据库的过程


rails new my_app -0

1. Remove database adapter gems from your Gemfile (mysql2, sqlite3, etc.)
 
2. Change your config/application.rb
 
Remove require 'rails/all line and require frameworks you want to use, for example:
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"
3. Delete your config/database.yml file, db/schema.rb and migrations (if any)
4. Delete migration check in test/test_helper.rb
5. Delete any ActiveRecord configuration from your config/environments files (this is what is causing your error)
这一步直接删除environments里所有的文件
This is all you need to do for an empty Rails app. If you run into problems caused by your existing code, stack trace should give you sufficient information on what you need to change. You might for example have some ActiveRecord configuration in your initializers.

6.删除controller里对Model的调用,把model里对ActiveRecord的依赖也删除

 

PS:方法二:请参考文章链接

http://stackoverflow.com/questions/19078044/disable-activerecord-for-rails-4

http://stackoverflow.com/questions/821251/how-to-configure-ruby-on-rails-with-no-database

 

你可能感兴趣的:(rails)