Rails 3에서 ActiveRecord 제거
이제 Rails 3 베타가 출시되었으므로 Rails 3 베타에서 방금 작업을 시작한 앱을 다시 작성해야한다고 생각했습니다. 두 가지 모두에 대한 느낌을 얻고 약간의 유리한 시작을 할 수 있습니다. 이 앱은 모든 모델에 MongoDB 및 MongoMapper를 사용하므로 ActiveRecord가 필요하지 않습니다. 이전 버전에서는 다음과 같은 방법으로 activerecord를 언로드합니다.
config.frameworks -= [ :active_record ] # inside environment.rb
최신 버전에서는 작동하지 않고 오류가 발생합니다.
/Library/Ruby/Gems/1.8/gems/railties-3.0.0.beta/lib/rails/configuration.rb:126:in
`frameworks': config.frameworks in no longer supported. See the generated
config/boot.rb for steps on how to limit the frameworks that will be loaded
(RuntimeError)
from *snip*
물론 boot.rb가 제안한대로 살펴 보았지만, 제가 볼 수있는 한 여기에서는 AR을 언로드하는 방법에 대한 단서가 없습니다. 내가이 작업을해야하는 이유는 내가 원하지 않는 것을로드하는 것이 어리 석을뿐만 아니라 컨트롤러 용 제너레이터를 실행하려고해도 DB 연결을 할 수 없다는 불만이 있기 때문입니다. 이것은 MongoDB 연결 세부 정보에 database.yml database.yml
을 사용 하는 데이 요지 를 사용 하기 위해 MongoDB에 대한 연결 세부 정보로 지우고 교체 했기 때문 입니다. 어쨌든 컨트롤러를 생성하기 위해 DB 연결을 시작할 수 있어야하는 이유를 모르겠습니다 ....
이 작업을 수행하는 올바른 Rails 3 방법을 알고있는 사람이 있습니까?
나는 소스를 읽음으로써 이것으로 갈 것이므로 실제로 작동하는지 알려주십시오. :)
rails
이제 응용 프로그램 템플릿을 생성하는 명령은 옵션이 -O
는 액티브을 건너 알려줍니다.
다시 실행 rails
하고 싶지 않다면 기존 앱에서 다음 사항을 확인해야합니다.
당신이 있는지 확인
config/application.rb
하지 않습니다 이require 'rails/all'
나require "active_record/railtie"
. 대신 ActiveRecord가없는 표준 Rails 설정의 경우 다음 사항 만 필요합니다.require File.expand_path('../boot', __FILE__) require "action_controller/railtie" require "action_mailer/railtie" require "active_resource/railtie" require "rails/test_unit/railtie" require "sprockets/railtie" # Auto-require default libraries and those for the current Rails environment. Bundler.require :default, Rails.env
에, 경우
config/application.rb
, 당신이 사용하는config.generators
섹션을 확인하십시오 그것은 선이 없습니다g.orm :active_record
.nil
원하는 경우 이를 명시 적으로로 설정할 수 있지만이g.orm
완전히 생략 된 경우 기본값이어야합니다 .선택 사항이지만에서 데이터베이스에 대한 모듈을로드하는 줄을
Gemfile
제거gem
합니다.gem "mysql"
예를 들어 이것은 라인이 될 수 있습니다 .
레일스 4
레일 4에서 비활성화하는 방법을 찾고 있었는데 레일 4에서 더 이상 작동하지 않는이 답변 만 찾았습니다. 그래서 이것은 레일 4에서 할 수있는 방법입니다 (RC1에서 테스트 됨).
새 프로젝트에서
rails new YourProject --skip-active-record
기존 프로젝트에서
- Gemfile에서 데이터베이스 드라이버 gem (예 :
gem 'sqlite3'
또는gem 'pg'
. config / application.rb에서 다음으로 대체하십시오
require 'rails/all'
."action_controller / railtie"필요 "action_mailer / railtie"필요 "스프로킷 / 레일 타이"필요 "rails / test_unit / railtie"필요
config / environments / development.rb에서 제거하거나 주석 처리하십시오.
config.active_record.migration_error = :page_load
잠재적으로 spec_helper에서 active_record 도우미를 제거해야합니다 (댓글의 VenoM을 통해).
Potentially you have to remove the ConnectionManagement middleware (seems to be the case with unicorn):
config.app_middleware.delete "ActiveRecord::ConnectionAdapters::ConnectionManagement"
(via https://stackoverflow.com/a/18087332/764342)
I hope this helps others looking for how to disable ActiveRecord in Rails 4.
For a new rails app, you can have it exclude active record by specifying the --skip-active-record parameter. Eg:
rails new appname --skip-active-record
If you generated a new project using Rails 3.2, you will also need to comment out:
config.active_record.mass_assignment_sanitizer = :strict
and
config.active_record.auto_explain_threshold_in_seconds = 0.5
in your development.rb file.
All of the above are true. The one more thing which I had to do in rails 3.1 is to comment out
config.active_record.identity_map = true
in config/application.rb
.
If you're running rspec, you also need to remove (in spec_helper):
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
and remove
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
Also comment out
# config/application.rb
config.active_record.whitelist_attributes = true
(noted on rails 3.2.13)
참고URL : https://stackoverflow.com/questions/2212709/remove-activerecord-in-rails-3
'program tip' 카테고리의 다른 글
Proguard를 사용할 때 특정 패키지 경로를 유지 / 제외하는 방법은 무엇입니까? (0) | 2020.08.20 |
---|---|
파이썬에서“EOF가 아닐 때”에 대한 완벽한 대응은 무엇입니까? (0) | 2020.08.20 |
WSDL 파일에서 Visual Studio에서 웹 서비스 프록시 만들기 (0) | 2020.08.20 |
JSTL forEach 루프의 varStatus를 ID로 사용 (0) | 2020.08.20 |
하나 이상의 일치하는 빈이 발견되면 Spring은 어떻게 이름으로 자동 연결됩니까? (0) | 2020.08.19 |