데이터베이스없이 Ruby on Rails를 구성하는 방법은 무엇입니까?
현재 데이터베이스가 필요없는 소규모 웹 사이트 프로젝트에 Ruby on Rails를 사용하는 것이 편리합니다. MySQL에서 빈 데이터베이스를 만들고 거기에서 갈 수 있다는 것을 알고 있지만 데이터베이스없이 Rails를 실행하는 더 좋은 방법을 아는 사람이 있습니까?
감사
environment.rb
파일 에서 다음 줄의 주석 처리를 제거 하십시오.
config.frameworks -= [ :active_record, :active_resource, :action_mailer]
들어 레일 3 및 레일 4 :
데이터베이스없이 애플리케이션을 생성 하려면
-O
(대문자 'O') 또는--skip-activerecord
옵션을 사용하십시오 .
rails new myApp -O
또는
rails new myApp --skip-activerecord
들어 레일 5 :
--skip-active-record
옵션을 사용 하여 데이터베이스없이 애플리케이션 생성
이전 Rails 버전과 달리 추가 하이픈 '-'를 확인하세요 .
rails new myApp --skip-active-record
기존 Rails 4/5/6 프로젝트의 경우 config/application.rb
파일에 다음 행이 있습니다.
require 'rails/all'
(해당 행 이이 파일을 로드하고 있음을 참조 )
따라서 모두로드하는 대신 다음과 같이 각 라이브러리를 개별적으로로드해야합니다.
# active_record is what we're not going to use it, so comment it "just in case"
# require "active_record/railtie"
# This is not loaded in rails/all but inside active_record so add it if
# you want your models work as expected
require "active_model/railtie"
# And now the rest
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "active_job/railtie" # Only for Rails >= 4.2
require "action_cable/engine" # Only for Rails >= 5.0
require "active_storage/engine" # Only for Rails >= 5.2
require "action_mailbox/engine" # Only for Rails >= 6.0
require "action_text/engine" # Only for Rails >= 6.0
require "sprockets/railtie"
require "rails/test_unit/railtie"
Rails 버전과 관련하여 무엇을로드해야하는지 알기 위해 주석을 주시하십시오. 그런 다음 다음 줄도 주석 처리하십시오.
#config/environments/development.rb
config.active_record.migration_error = :page_load
config.active_record.verbose_query_logs = true
#config/environments/production.rb
config.active_record.dump_schema_after_migration = false
#spec/rails_helper.rb
ActiveRecord::Migration.maintain_test_schema!
# Only for Rails >= 5.0
#config/initializers/new_framework_defaults.rb
Rails.application.config.active_record.belongs_to_required_by_default = true
선택적으로 class에 대한 참조를 삭제할 수 ActiveRecord
있습니다.
rm app/models/application_record.rb
업데이트 : ' Rails 3-데이터베이스를 완전히 피하려면 어떻게해야합니까? 'Rails 3에서이 작업을 수행하는 방법에 대한 질문입니다.
새로운 프로젝트를 시작할 때 Rails 4에서 -O 또는 --skip-active-record를 사용할 수 있습니다.
rails new my_project -O
rails new my_project --skip-active-record
이미 프로젝트를 생성했다면 댓글을 달아야합니다.
require "active_record/railtie"
config / application.rb 및
config.active_record.migration_error = :page_load
config / environments / development.rb에서
If you don't need a database then you probably don't need to have the bulk of Rails. You may want a smaller more customizable framework to work with.
Sinatra is a tiny framework that is great for serving up basic static pages.
But if you insist on using Rails here is an article that will show you how to do just that or here.
For support Rails 6 rc1 and activerecord-nulldb-adapter
gem we need a monkey patching
In config/initializers/null_db_adapter_monkey_patches.rb
module ActiveRecord
module ConnectionAdapters
class NullDBAdapter < ActiveRecord::ConnectionAdapters::AbstractAdapter
def new_table_definition(table_name = nil, is_temporary = nil)
TableDefinition.new(table_name, is_temporary)
end
end
end
end
참고URL : https://stackoverflow.com/questions/821251/how-to-configure-ruby-on-rails-with-no-database
'Programing' 카테고리의 다른 글
WCF 오류- 'UserService.UserService'계약을 참조하는 기본 끝점 요소를 찾을 수 없습니다. (0) | 2020.08.24 |
---|---|
ID에 대한 변수를 사용하여 jQuery에서 요소를 어떻게 선택합니까? (0) | 2020.08.24 |
자동 여백이 페이지의 중앙에 있지 않음 (0) | 2020.08.24 |
한 번에 여러 파일의 EOL 변경 (0) | 2020.08.24 |
Android 정적 개체 수명주기 (0) | 2020.08.24 |