Rails upgrade 5.2 to 6.0


Server/Ruby on the Rails 2019.05.24 21:33



Rails 5.2.0 to 6.0.0 

* 6.0 에서 ActionText를 사용할 수 있다! 흥미로움

 

1. Rails 6은 Ruby 2.5.0 이상 버전에서 동작 

2. rails app:update 를 실행

3. config.load_defaults in config/application.rb 변경하기 

 

config.load_defaults 6.0

 

application.rb에 Rails.autoloaders.logger = method(:puts) 입력 시 레일즈 시작할때 autoloads되는 것들을 볼 수 있음. 


https://edgeguides.rubyonrails.org/6_0_release_notes.html

 

Ruby on Rails 6.0 Release Notes — Ruby on Rails Guides

Ruby on Rails 6.0 Release NotesHighlights in Rails 6.0: Action Mailbox Action Text Parallel Testing Action Cable Testing These release notes cover only the major changes. To learn about various bug fixes and changes, please refer to the change logs or chec

edgeguides.rubyonrails.org

https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#common-gotchas

 

Autoloading and Reloading Constants — Ruby on Rails Guides

Ruby on Rails allows applications to be written as if their code was preloaded. In a normal Ruby program classes need to load their dependencies: require 'application_controller' require 'post' class PostsController < ApplicationController def index @posts

guides.rubyonrails.org

 

원인을 찾는 중 

 

상속관계
ApplicationController (get_current_user)
AdminController (before_action: verify_admin 내에서 ApplicationController의 get_current_user 호출 불가)

BController  

....대체 왜 6.0에서는 불가능한것이지?
원인은 찾음. 6.0부터는 autoloading 방식이 :zeitwerk이 기본
(방식에는 :zeitwerk and :classic 두가지가 존재하는데, 6.0 이전에는 :classic 방식을 사용했었음)
만약 서비스 중인 어플리케이션이라면, application.rb 에 config.autoloader = :classic으로 세팅 후 사용하는 것이 나을 듯 
zeitwerk autoload 방식은 https://mnworld.co.kr/1909 으로 업데이트 중

 

https://weblog.rubyonrails.org/2019/2/22/zeitwerk-integration-in-rails-6-beta-2/

 

Zeitwerk integration in Rails 6 (Beta 2)

The second beta of Rails 6 is about to ship, and includes Zeitwerk integration.

weblog.rubyonrails.org

https://github.com/fxn/zeitwerk/issues/19

 

eager_load difference between autoloader classic, bug or feature? · Issue #19 · fxn/zeitwerk

Hi, I noticed that when I used config.eager_load=true or ran the Jumpstart template in production which overrides the Devise helper https://github.com/excid3/jumpstart/blob/c6c0de0a9493c617297746eb...

github.com

https://medium.com/@fxn/zeitwerk-a-new-code-loader-for-ruby-ae7895977e73

 

Zeitwerk: A new code loader for Ruby

This post presents Zeitwerk: A new code loader for Ruby in which I have been working during the last months.

medium.com

skip_before_action :verify_authenticity_token 이슈도 살펴봐야 함

 

수정 시 puma가 controller 로딩 못하는 상황 

begin
  load File.expand_path('../spring', __FILE__)
rescue LoadError => e
  raise unless e.message.include?('spring')
end

bin/rails에 추가 



model에 override된 메서드가 동작을 안함..

-> https://github.com/rails/rails/issues/36100

-> https://github.com/rails/rails/issues/35749

 

Zeitwerk breaks override pattern · Issue #36100 · rails/rails

Steps to reproduce Follow https://edgeguides.rubyonrails.org/engines.html#overriding-models-and-controllers create an override (monkey patch) for a class This works before 6.0.0.rc1 (including 6.0....

github.com

Override 이슈 -> 해당이슈도 https://mnworld.co.kr/1909에서 같이 정리 중.

 

그 외,

features.where(awesomeness: 10..) 와 같이 endless ranges가 가능
bin/rails db:system:change --to=postgresql 명령어를 쓰면 sqlite에서 postgresql로 바로 변경이 가능 


WRITTEN BY
ShakeJ

트랙백  0 , 댓글  0개가 달렸습니다.
secret