복붙노트

[RUBY-ON-RAILS] 어떻게 어떤 데이터베이스와 루비 온 레일즈를 구성?

RUBY-ON-RAILS

어떻게 어떤 데이터베이스와 루비 온 레일즈를 구성?

이 데이터베이스에 대한 현재의 필요가없는 작은 웹 사이트 프로젝트에 루비 온 레일즈를 사용하는 것이 편리 할 것입니다. 내가 MySQL의에서 빈 데이터베이스를 만들 수 있습니다 알고 거기에서 이동하지만, 사람이 데이터베이스없이 레일을 실행할 수있는 더 좋은 방법을 알고 있나요?

감사

해결법

  1. ==============================

    1.environment.rb에 파일이 줄을 주석 처리를 제거 :

    environment.rb에 파일이 줄을 주석 처리를 제거 :

    config.frameworks -= [ :active_record, :active_resource, :action_mailer]
    
  2. ==============================

    2.레일 3 레일 4 :

    레일 3 레일 4 :

    새을 myApp의 -O 레일

    또는

    새을 myApp --skip-액티브 레일

    이 대답은 여기에서 재 공유한다

    레일 5 :

    여분의 하이픈 주목 '-'이전 레일 버전에 반대.

    새을 myApp는 레일 --skip-액티브 기록

  3. ==============================

    3.기존 레일 4/5/6 프로젝트, 당신의 설정 / application.rb 파일에 다음과 같은 라인을 가지고 :

    기존 레일 4/5/6 프로젝트, 당신의 설정 / application.rb 파일에 다음과 같은 라인을 가지고 :

    require 'rails/all' # or `require "rails"' in newer versions
    

    (참고로 광고 파일이로드된다) 그래서 그 대신 부하로, 개별적으로 다음 각 라이브러리를로드하려면 다음을 수행해야합니다

    # 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 "sprockets/railtie"
    require "rails/test_unit/railtie"
    
    # All these depend on active_record, so they should be excluded also
    # require "action_text/engine" # Only for Rails >= 6.0
    # require "action_mailbox/engine" # Only for Rails >= 6.0
    # require "active_storage/engine" # Only for Rails >= 5.2
    

    당신의 레일 버전에 대한로드 알고 코멘트에 눈을 유지합니다. 또한 (경우에 당신이 그들을 가지고에서) 다음 파일을 확인하고 다음 줄을 주석 :

    # package.json
    "@rails/activestorage": "^6.0.0",
    
    # app/javascript/packs/application.js
    require("@rails/activestorage").start()
    
    # bin/setup
    system! 'bin/rails db:prepare'
    
    # config/environments/development.rb
    config.active_storage.service = :local # For Rails >= 5.2
    config.active_record.migration_error = :page_load
    config.active_record.verbose_query_logs = true
    
    # config/environments/test.rb
    config.active_storage.service = :test # For Rails >= 5.2
    
    # config/environments/production.rb
    config.active_storage.service = :local # For Rails >= 5.2
    config.active_record.dump_schema_after_migration = false
    
    # spec/rails_helper.rb
    ActiveRecord::Migration.maintain_test_schema!
    
    # test/test_helper.rb
    fixtures :all # In case you're using fixtures
    
    # Only for Rails >= 5.0
    #config/initializers/new_framework_defaults.rb
    Rails.application.config.active_record.belongs_to_required_by_default = true
    

    또한 모델 파일에서 액티브 :: 자료에 대한 참조를 제거 (또는 적용 할 경우 단순히 파일을 삭제). 예를 들어, 자동 생성 된 응용 프로그램 / 모델 / application_record.rb 파일.

  4. ==============================

    4.업데이트 : (가) '3 레일 - 나는 모두 데이터베이스를 피하기 어떻게?'참조 레일 3이 일에 업데이트에 대한 질문입니다.

    업데이트 : (가) '3 레일 - 나는 모두 데이터베이스를 피하기 어떻게?'참조 레일 3이 일에 업데이트에 대한 질문입니다.

  5. ==============================

    5.새 프로젝트를 시작할 때 레일 4에서는 -O를 사용하거나 --skip-활성 기록을 할 수 있습니다

    새 프로젝트를 시작할 때 레일 4에서는 -O를 사용하거나 --skip-활성 기록을 할 수 있습니다

    rails new my_project -O
    rails new my_project --skip-active-record
    

    이미 프로젝트를 만들었다면 당신은 코멘트를해야합니다

     require "active_record/railtie"
    

    설정 / application.rb와에서

     config.active_record.migration_error = :page_load
    

    설정 / 환경 / development.rb에서

  6. ==============================

    6.그런 다음 데이터베이스가 필요하지 않은 경우 당신은 아마 레일의 대부분을 가질 필요가 없습니다. 당신은 작업 할 작은 더 사용자 정의 프레임 워크를 할 수 있습니다.

    그런 다음 데이터베이스가 필요하지 않은 경우 당신은 아마 레일의 대부분을 가질 필요가 없습니다. 당신은 작업 할 작은 더 사용자 정의 프레임 워크를 할 수 있습니다.

    시나는 기본 정적 페이지를 제공에 좋은 곳입니다 작은 프레임 워크입니다.

    하지만 당신은 여기에 레일을 사용하여 주장하면 어떻게 그냥 나 여기서 뭘 보여줍니다 기사입니다.

  7. ==============================

    7.지원은 6 RC1 및 액티브 - nulldb-adaptergem 레일을 위해 우리는 원숭이 패치가 필요합니다

    지원은 6 RC1 및 액티브 - nulldb-adaptergem 레일을 위해 우리는 원숭이 패치가 필요합니다

    에서 설정 / 초기화 / 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
    
  8. from https://stackoverflow.com/questions/821251/how-to-configure-ruby-on-rails-with-no-database by cc-by-sa and MIT license