Rails 5.2 업데이트 시 문제점 정리

Rails 5.2 업데이트 시 문제점 정리

개인 프로젝트로 관리중인 rails web serverruby version 을 올리는 김에 같이 업데이트를 하려고 합니다.

기존 버전은 rails 5.0.3 이었고, 이번에 rails 5.2.0 으로 올리고 만난 에러들을 기록하려고 글을 씁니다.

Update

먼저 Gemfile.lock 을 지우고 과감하게 update 룰 합니다.

rm Gemfile.lock
bundle update

Gemfile 을 열어보면 rails 5.2를 확인할 수 있습니다.

업데이트가 안되었다면, 강제로 rails 만 업데이트 해줍니다.

bundle update rails -v 5.2.0

내가 만난 문제들


“Rack::Cors” String 문제

업데이트가 잘 되었으면 console 을 실행합니다.

rails c

output

$ rails c
/Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/stack.rb:37:in `build': undefined method `new' for "Rack::Cors":String
Did you mean?  next (NoMethodError)
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/stack.rb:101:in `block in build'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/stack.rb:101:in `each'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/stack.rb:101:in `inject'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/stack.rb:101:in `build'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/engine.rb:510:in `block in app'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/engine.rb:506:in `synchronize'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/engine.rb:506:in `app'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/initializable.rb:32:in `instance_exec'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/initializable.rb:32:in `run'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/initializable.rb:61:in `block in run_initializers'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:228:in `block in tsort_each'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `each'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `call'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `each_strongly_connected_component'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:226:in `tsort_each'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:205:in `tsort_each'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/initializable.rb:60:in `run_initializers'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application.rb:361:in `initialize!'
    from /Users/ktg/privates/my_projects/config/environment.rb:5:in `<top (required)>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `block in require'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:102:in `preload'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    from -e:1:in `<main>'

위의 에러가 났습니다.

이 에러는 application.rb 내부의 Rack::Cors 문제입니다. 아래 링크에 해결책이 자세히 나와있습니다.

ruby – Error when running Rails application – Stack Overflow

raise_in_transactional_callbacks 문제

/Users/ktg/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `raise_in_transactional_callbacks=' for ActiveRecord::Base:Class (NoMethodError)
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/railtie.rb:124:in `block (3 levels) in <class:Railtie>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/railtie.rb:123:in `each'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/railtie.rb:123:in `block (2 levels) in <class:Railtie>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:71:in `instance_eval'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:51:in `each'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/base.rb:328:in `<module:ActiveRecord>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/base.rb:27:in `<top (required)>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `block in require'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:247:in `block in load_dependency'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:653:in `new_constants_in'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:247:in `load_dependency'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
    from /Users/ktg/privates/my_projects/app/models/application_record.rb:1:in `<top (required)>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:468:in `load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:468:in `block in load_file'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:653:in `new_constants_in'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:467:in `load_file'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:365:in `block in require_or_load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:37:in `block in load_interlock'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies/interlock.rb:13:in `loading'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:37:in `load_interlock'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:348:in `require_or_load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:502:in `load_missing_constant'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:193:in `const_missing'
    from /Users/ktg/privates/my_projects/app/models/user.rb:1:in `<top (required)>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:468:in `load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:468:in `block in load_file'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:653:in `new_constants_in'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:467:in `load_file'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:365:in `block in require_or_load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:37:in `block in load_interlock'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies/interlock.rb:13:in `loading'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:37:in `load_interlock'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:348:in `require_or_load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:502:in `load_missing_constant'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:193:in `const_missing'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/inflector/methods.rb:283:in `const_get'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/inflector/methods.rb:283:in `block in constantize'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/inflector/methods.rb:281:in `each'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/inflector/methods.rb:281:in `inject'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/inflector/methods.rb:281:in `constantize'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:574:in `get'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:605:in `constantize'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise.rb:316:in `get'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise/mapping.rb:83:in `to'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise/mapping.rb:78:in `modules'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise/mapping.rb:95:in `routes'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise/mapping.rb:162:in `default_used_route'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise/mapping.rb:72:in `initialize'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise.rb:346:in `new'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise.rb:346:in `add_mapping'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:243:in `block in devise_for'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:242:in `each'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:242:in `devise_for'
    from /Users/ktg/privates/my_projects/config/routes.rb:8:in `block in <top (required)>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:432:in `instance_exec'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:432:in `eval_block'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:414:in `draw'
    from /Users/ktg/privates/my_projects/config/routes.rb:1:in `<top (required)>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:277:in `load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:277:in `block in load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:277:in `load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/routes_reloader.rb:57:in `block in load_paths'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/routes_reloader.rb:57:in `each'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/routes_reloader.rb:57:in `load_paths'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/routes_reloader.rb:20:in `reload!'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/routes_reloader.rb:43:in `block in updater'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/file_update_checker.rb:83:in `execute'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/routes_reloader.rb:44:in `updater'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/routes_reloader.rb:33:in `execute_if_updated'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/finisher.rb:130:in `block in <module:Finisher>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/initializable.rb:32:in `instance_exec'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/initializable.rb:32:in `run'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/initializable.rb:61:in `block in run_initializers'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:228:in `block in tsort_each'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `each'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `call'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `each_strongly_connected_component'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:226:in `tsort_each'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:205:in `tsort_each'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/initializable.rb:60:in `run_initializers'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application.rb:361:in `initialize!'
    from /Users/ktg/privates/my_projects/config/environment.rb:5:in `<top (required)>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `block in require'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:102:in `preload'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    from -e:1:in `<main>'

application.rb에 있는 하단 내용을 삭제 합니다.

config.active_record.raise_in_transactional_callbacks = true

하단 내용 참고

https://stackoverflow.com/questions/37464966/what-causes-deprecation-warning-activerecordbase-raise-in-transactional-callb

Coffeescript Error

이제 레일즈 서버를 실행하고 접속해봅니다.

$ rails s
$ curl localhost:3000

Output

=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run `rails server -h` for more startup options
[32087] Puma starting in cluster mode...
[32087] * Version 3.11.4 (ruby 2.5.1-p57), codename: Love Song
[32087] * Min threads: 5, max threads: 5
[32087] * Environment: development
[32087] * Process workers: 2
[32087] * Preloading application
[32087] * Listening on tcp://0.0.0.0:3000
[32087] Use Ctrl-C to stop
[32087] - Worker 0 (pid: 32090) booted, phase: 0
[32087] - Worker 1 (pid: 32091) booted, phase: 0
Started GET "/" for 127.0.0.1 at 2018-05-29 23:37:10 +0900
   (0.4ms)  SET  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
   (0.3ms)  SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
Processing by MainController#index as HTML
Completed 401 Unauthorized in 14ms (ActiveRecord: 0.0ms)


Started GET "/login" for 127.0.0.1 at 2018-05-29 23:37:10 +0900
Processing by Devise::SessionsController#new as HTML
  Rendering devise/sessions/new.html.erb within layouts/application
  Rendered devise/shared/_links.html.erb (1.0ms)
  Rendered devise/sessions/new.html.erb within layouts/application (16.6ms)
Completed 500 Internal Server Error in 6804ms (ActiveRecord: 1.4ms)



LoadError (cannot load such file -- coffee_script):

app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb___3099409563303512009_70257788966240'

NameError: uninitialized constant Mime::HTML
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/web-console-2.3.0/lib/web_console/middleware.rb:58:in `acceptable_content_type?'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/web-console-2.3.0/lib/web_console/middleware.rb:36:in `block in call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `catch'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/rack/logger.rb:38:in `call_app'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/rack/logger.rb:26:in `block in call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:71:in `block in tagged'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:28:in `tagged'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:71:in `tagged'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/rack/logger.rb:26:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/request_id.rb:27:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/rack-2.0.5/lib/rack/method_override.rb:22:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/rack-2.0.5/lib/rack/runtime.rb:22:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/executor.rb:14:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/static.rb:127:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/rack-cors-1.0.2/lib/rack/cors.rb:97:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/engine.rb:524:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/configuration.rb:225:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/server.rb:632:in `handle_request'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/server.rb:446:in `process_client'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/server.rb:306:in `block in run'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/thread_pool.rb:120:in `block in spawn_thread'
Started GET "/assets/css/main.min.css" for 127.0.0.1 at 2018-05-29 23:37:18 +0900

ActionController::RoutingError (No route matches [GET] "/assets/css/main.min.css"):

actionpack (5.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.0) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.0) lib/rails/rack/logger.rb:26:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.5) lib/rack/method_override.rb:22:in `call'
rack (2.0.5) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.5) lib/rack/sendfile.rb:111:in `call'
rack-cors (1.0.2) lib/rack/cors.rb:97:in `call'
railties (5.2.0) lib/rails/engine.rb:524:in `call'
puma (3.11.4) lib/puma/configuration.rb:225:in `call'
puma (3.11.4) lib/puma/server.rb:632:in `handle_request'
puma (3.11.4) lib/puma/server.rb:446:in `process_client'
puma (3.11.4) lib/puma/server.rb:306:in `block in run'
puma (3.11.4) lib/puma/thread_pool.rb:120:in `block in spawn_thread'

NameError: uninitialized constant Mime::HTML
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/web-console-2.3.0/lib/web_console/middleware.rb:58:in `acceptable_content_type?'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/web-console-2.3.0/lib/web_console/middleware.rb:36:in `block in call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `catch'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/rack/logger.rb:38:in `call_app'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/rack/logger.rb:26:in `block in call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:71:in `block in tagged'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:28:in `tagged'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:71:in `tagged'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/rack/logger.rb:26:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/request_id.rb:27:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/rack-2.0.5/lib/rack/method_override.rb:22:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/rack-2.0.5/lib/rack/runtime.rb:22:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/executor.rb:14:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/static.rb:127:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/rack-cors-1.0.2/lib/rack/cors.rb:97:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/engine.rb:524:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/configuration.rb:225:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/server.rb:632:in `handle_request'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/server.rb:446:in `process_client'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/server.rb:306:in `block in run'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/thread_pool.rb:120:in `block in spawn_thread'

엄청나게 긴 에러를 만납니다.
원인을 찾아보니, 원인은 단순합니다.
사용하지 않는 coffeescript 파일들이 프로젝트에 존재하고 있었습니다.

아래 명령으로 확인후 삭제 해줍니다.

$ find . -name "*.coffee"

그러고도 에러가 난다면 **cache*** 문제입니다.

cache 를 삭제해줍니다.

$ rake tmp:cache:clear

관련 내용은 여기서 확인 가능합니다.

web-console 문제

위의 에러에서

NameError: uninitialized constant Mime::HTML
이런 에러가 있는데 이건 web-console 버전 문제였습니다..

web-console을 업데이트 해줍니다.

$ bundle update web-console

다시 실행합니다.

결론


여기까지 제가 해결한 문제였습니다.

Font awesome 아이콘 정렬 문제

Font awesome 아이콘 정렬 문제

상황

현재 Bootstrap 4 를 사용해서 프로젝트를 진행 중입니다.
bootstrap 4는 버전이 beta 상태로 있지만 어차피 나중엔 쓸테니까 처음으로 시작하는 프로젝트는 모두 bootstrap 4 로 작성 중 입니다.

Bootstrap 4 에는 기존에 있던 Glyphicons 가 사라졌습니다.

링크 참조 Migrating to v4 · Bootstrap

그래서 기존 Glyphicons 를 사용하지 않고 아이콘 버튼을 만들기 위해 font awesome 을 사용하게 되었습니다.

GitHub – Justineo/vue-awesome: Awesome SVG icon component for Vue.js, built-in with Font Awesome icons.

설치하면 font-awesome 이 내장되어 있습니다.

글 작성일 현재 README 문구를 보면 버전을 확인 할 수 있습니다.

Vue-Awesome is built upon Font Awesome v4.5.0 and depends on Vue.js v2.0.1+.

문제점

Vue-awesome code using Pug

icon(name='archive')
span Zones

Font-awesome 에 있는 아이콘과 link를 생성해보면 아래 이미지와 같은 align 관련 문제점을 확인 할 수 있습니다.

http://blog.uniqbuild.co.kr/wp-content/uploads/2017/09/picture-bootstrap-noalign.png

해결

Icon inside bootstrap button · Issue #52 · Justineo/vue-awesome · GitHub
여기에서 보이는 것처럼 css 를 추가해 줍니다.

저는 .btn class 는 사용하지 않으므로 제외 했습니다.

.fa-icon {
    vertical-align: middle;
    margin-right: 0.5rem;
}

입력 후, 화면을 확인하시면 아래와 같이 아이콘이 정렬된 모습을 확인 할 수 있습니다.

http://blog.uniqbuild.co.kr/wp-content/uploads/2017/09/picture-bootstrap-align.png

크로스 도메인 이슈

서문

요즘 마이크로 서비스가 대세입니다.
저는 요즘 Vuejs 를 이용한 Web app 을 만들려고 시도 중입니다.
이 웹앱을 마이크로 서비스로 만들려합니다. 이러한 경우에 만나는 문제가 바로 크로스 도메인 문제, CORS(Cross Origin Resource Sharing) 이슈입니다.

환경

현재 시스템은 localhost:8080 에 떠있는 RESTful API Server 에. localhost:8082에 떠있는 Web App 에서 http 요청을 해서 데이터를 가져오는 형태입니다.

문제점

간단한 SPA(Single Page Application) 어플을 만들 때, 이 웹 어플리케이션에 채워지는 데이터는 REST API 를 이용, 비동기 네트워크 통신으로 API 서버와 WEB APP의 서버가 다른 경우가 생깁니다.

이때 Web app 에서 ajax를 이용해서 REST API 를 호출하면 Browser console window 에서 이런 에러를 만나게 됩니다.

XMLHttpRequest cannot load http://localhost:8080/v1/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8082' is therefore not allowed access.

원인

보안 상의 이유로, 브라우저들은 스크립트 내에서 초기화되는 cross-origin HTTP 요청을 제한하기 때문입니다.

해결책

간단합니다.
RESTful API서버의 RESPONSE HEADER 에 하나만 추가해주면 됩니다.

Access-Control-Allow-Origin: *

만약 특정 도메인만 허용하고 싶다면,

Access-Control-Allow-Origin: http://test.com, http://test2.com, …

이런 형태로 사용하시면 됩니다.

[android] AsyncTask too late problem..

안드로이드 AsyncTask

android AsyncTask 는 안드로이드에서 자주쓰고, 자주 보는 클래스이다.

우리 회사에서 서비스중인 안드로이드 앱에서도 AsyncTask를 많이 쓰고 있다.

그런데, 회사에서 서비스 중인 안드로이드가 너무 느려서 원인을 찾기위해 이것저것 로그를 찍어본 결과.
AsyncTask를 실행하고, doInBackground() 호출이 너무 느렸다. 무려 3초에서 4초정도 딜레이가 되고 있었다.

원인을 열심히 찾아봤는데 허니콤 이전 버전에선 AsyncTask의 개수제한이 있었다.

core pool size와 max pool size가 있었던것 같은데, 필요하면 아래 글 참고 하면 될듯.

AsyncTask 참고1
AsyncTask 참고2

수정하려고 봤더니 여기저기 AsyncTask를 마구마구 쓰고 있고, 여러 depth에 걸처서 부르는 로직도 있어서 수정 규모가 너무 크다고 판단.

일단 심플하게 thread를 이용해서 AsyncTask역할을 그대로 하는 코드를 만들었다.

Why?

AsyncTask 자리에 그대로 바꿔치기 하기 위함이다.
일단 이것으로 속도확보를 했으니 다음 차례는 쓰레드 풀이든 스케쥴링이던 하면 될 듯하고. 일단 지금은 스케쥴러를 별도로 만들어 관리하도록 수정.

혹시 몰라서 여기에 올려놓는다. 자료 백업 목적 및 필요한 사람들이 있을지도 모르니 공유의 목적도…

/****
 * title: AsyncThread
 * description: Simple thread extension like AsyncTask. 
 * 				But the AsyncThread is non atomic no use thread pool.
 *
 * author: weep
 * blog: weeppp.com
 * email: ktg@weeppp.com
 * Copyright (c) 2015 Teukgeon, Kwon. All rights reserved.
 ****/

package com.weeppp.tklib;

import android.os.Handler;
import android.os.Message;

public abstract class AsyncThread<Params, Progress, Result> extends Thread implements Runnable {
    protected void onPreExecute() {};
    abstract protected Result doInBackground(Params... params);
    protected void onPostExecute(Result result) {};
    protected void onCancell() {};

    Params[] params;
    static final int MESSAGE_POST_RESULT = 30;

    enum Status {
        PENDING,
        RUNNING,
        FINISHED
    }

    private Status status = Status.PENDING;
    private boolean isCancel = false;
    final InternalHandler internalHandler = new InternalHandler();

    public AsyncThread()
    {

    }

    public AsyncThread<Params, Progress, Result> execute(Params... params)
    {
        if (status != Status.PENDING) {
            switch (status) {
                case RUNNING:
                    throw new IllegalStateException("Cannot execute task:"
                            + " the task is already running.");
                case FINISHED:
                    throw new IllegalStateException("Cannot execute task:"
                            + " the task has already been executed "
                            + "(a task can be executed only once)");
                default:
                    break;
            }
        }
        status = Status.RUNNING;

        this.params = params;
        onPreExecute();
        start();
        return this;
    }

    public final Status getStatus() {
        return status;
    }

    public final boolean isCancelled() {
        return isCancel;
    }

    public final boolean cancel() {
        isCancel = true;
        return isCancel;
    }

    public final boolean cancel(boolean mayInterruptIfRunning) {
        isCancel = true;
        return isCancel;
    }

    public void run()
    {
        final Result result = doInBackground(params);

        Message msg = internalHandler.obtainMessage(MESSAGE_POST_RESULT);
        msg.obj = new AsyncResult(this, result);
        internalHandler.sendMessage(msg);
    }

    protected void onCancell(Result result)
    {
        onCancell();
    }

    private void finish(Result result)
    {
        if (isCancelled()) {
            onCancell(result);
        }
        else {
            onPostExecute(result);
        }
        status = Status.FINISHED;
    }

    private static class InternalHandler extends Handler {
        @SuppressWarnings({"unchecked"})
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MESSAGE_POST_RESULT:
                    AsyncResult aResult = (AsyncResult)msg.obj;
                    aResult.thread.finish(aResult.result);
                    break;
            }
        }
    }

    @SuppressWarnings({"rawtypes"})
    static class AsyncResult {
        final AsyncThread thread;
        final Object result;
        public AsyncResult(AsyncThread thread, Object result)
        {
            this.thread = thread;
            this.result = result;
        }
    }
}