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

다시 실행합니다.

결론


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

HTML
tag self closing issue

Rails 개발 중 의문의 버그

환경

  • Ruby 2.3.4
  • Rails 5.0.4

증상

<div class="modal fade">
...
<%= form_tag "/videos", method: 'get' do %>
  <%= select_tag(:environment_id, options_for_select(['dev','prod']), class: "form-control", include_blank: true, onchange: "this.form.submit();") %>
<% end %>
...
</div>

이런 형태의 erb를 만들어서 view 안에서 render 로 view 를 부분적으로 생성했습니다.

그런데!

<form method=“get”  accept-charset="UTF-8"></form>
<select ...

이런 식으로 form tag 가 지맘대로 닫히고 그 아래에 select 태그가 생겼습니다.

이것 때문에 onchange 의 스크립트에서 문제가 생겼습니다.

해결

구글링을 하던 중..

루비 포럼에서 Form tag self closing 이라는 글을 발견했습니다.

참고: form tag is self-closing before input fields (HAML generator used)

문제는 이것
That's not legal markup. Either wrap the form around the entire table or put it completely inside a cell.

<td> 태그안으로 modal view를 넣어서 해결했습니다.

RoR (rails) Dockerfile tip

RoR (rails) Dockerfile tip

루비 온 레일즈 (Ruby on Rails)를 Docker 로 배포할 때 간단 팁입니다.

Rails 를 도커로 배포할 때 가장 큰 문제는 Rebuild 시간이 오래걸린다는 것입니다.

원인은 바로 bundler !!

$ bundle install

이놈이 오래걸립니다.

하여 예전에 이 Article 을 보고 적용해서 쓰던 중 보다 괜찮은 방법이 있어서 기록합니다.

Prerequisite

  • ruby 2.3.4
  • Rails 5.1.2
  • docker 17.06-ce

Rails on Docker

제가 쓰는 Dockerfile 을 아래 공유합니다.

FROM ruby:2.3.4-slim
LABEL maintainer="9to5, ktk0011+dev@gmail.com"

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    build-essential git libpq-dev nodejs vim libxslt-dev libxml2-dev cron && \
    rm -rf /var/lib/apt/lists/*

ENV INSTALL_PATH /app
WORKDIR $INSTALL_PATH

ENV BUNDLE_FROZEN=1 BUNDLE_DISABLE_SHARED_GEMS=true BUNDLE_WITHOUT=development:test

ADD ./bin $INSTALL_PATH/bin
COPY Gemfile Gemfile.lock ./
RUN bin/bundle install --deployment

ADD . $INSTALL_PATH

기존과의 차이점은 BUNDLE_FROZEN 을 이용해서 더이상 Gem변경을 허용하지 않으며,
BUNDLE_DISABLE_SHARED_GEMS 설정으로 번들 path를 고정하고,

BUNDLE_WITHOUT 을 이용해서 오직 deployment 환경을 대상으로만 bundle 을 관리합니다.

Conclusion

이런 형태로 사용한다면 docker 로 변경된 내용을 배포할 때 마다 bundler 때문에 시간이 소모되는 문제를 쉽게 해결 가능합니다.

CentOS7에 Discourse 설치 및 서비스 시작하기

1. redis install

$> sudo yum install -y epel-release
$> sudo rpm -ivh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
$> sudo yum --enablerepo=remi update remi-release
$> sudo systemctl start redis.service
$> sudo systemctl enable redis.service
$> sudo systemctl status redis.service

status 실행 후

● redis.service - Redis persistent key-value database
   Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/redis.service.d
           └─limit.conf
   Active: active (running) since Thu 2016-06-30 16:31:27 KST; 1 weeks 3 days ago

위처럼 active 상태가 나타나면 정상 동작 중이다.

2. postgresql 설치

$> sudo yum install -y postgresql-server postgresql-contrib postgresql-libs postgresql-devel
$> sudo postgresql-setup initdb
$> sudo systemctl start postgresql
$> sudo systemctl enable postgresql
$> sudo systemctl status postgresql

postresql 도 위의 redis와 마찬가지로 active 상태가 나오면 정상동작 중이다.

3. rvm install for multi users

루비 설치가 필요하다. 상세 내용은 예전 포스팅을 참조한다.

http://weeppp.com/?p=93

$> sudo gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
$> sudo curl -sSL https://get.rvm.io | sudo bash -s stable

rvm 그룹에 자신의 user id를 추가한다.

$> sudo vi /etc/group
...

rvm:x:505:user,user2,user3

 

logout 후 재접속 한다. 환경 설정 리로드를 위함

# restart
$> type rvm | head -n 1
rvm is a function

위의 내용이 출력되면 정상 설치

$> rvm install 2.3.1
$> rvm use 2.3.1@newgemset --create --default
$> gem update
$> gem install bundler

4. Node install

$> curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash
# exit the terminal and open it again

logout 후에 다시 재접속한다.

$> nvm install 6.2.0
$> nvm alias default 6.2.0
$> npm install -g svgo phantomjs-prebuilt

 

5. discourse install

하단 링크 참조

https://github.com/discourse/discourse/blob/master/docs/DEVELOPER-ADVANCED.md

필요한 라이브러리들 설치

$> sudo yum install -y expect git-core ImageMagick* advancecomp gifsicle jhead jpegoptim optipng pngcrush pngquant

 

db 설정

여기서는 development, production database를 모두 만든다.

하단 ‘password’ 부분에 원하는 암호를 입력한다.

$> whoami > /tmp/username
$> sudo su postgres
$> createuser --createdb --superuser -Upostgres $(cat /tmp/username)
$> psql -c "ALTER USER $(cat /tmp/username) WITH PASSWORD 'password';"
$> psql -c "create database discourse_development owner $(cat /tmp/username) encoding 'UTF8' TEMPLATE template0;"
$> psql -c "create database discourse_test owner $(cat /tmp/username) encoding 'UTF8' TEMPLATE template0;"
$> psql -c "create database discourse owner $(cat /tmp/username) encoding 'UTF8' TEMPLATE template0;"
$> psql -d discourse_development -c "CREATE EXTENSION hstore;"
$> psql -d discourse_development -c "CREATE EXTENSION pg_trgm;"
$> psql -d discourse -c "CREATE EXTENSION hstore;"
$> psql -d discourse -c "CREATE EXTENSION pg_trgm;"
$> exit

 

discourse 설치

$> git clone https://github.com/discourse/discourse.git ~/discourse
$> cd ~/discourse
$> bundle install
$> bundle exec rake db:create db:migrate db:test:prepare

개발 모드로 실행 확인

$> bundle exec sidekiq -d -L log/sidekiq.log -C config/sidekiq.yml
$> thin start

 

이제 배포판을 설치해보려고 한다.

실제 이 포스팅은 production 모드 설치를 위해 쓰고 있는 것이므로 지금부터가 진짜다;;

 

설정 파일 생성

$> cd $(discourse_home)/config
$> cp discourse_defaults.conf discourse.conf

설정파일 수정

$> vi discourse.conf
# username accessing database
db_username = user_id

# password used to access the db
db_password = password

...

# hostname running the forum
hostname = "weeppp.com"

...

# enable if you really need to serve assets in prd
serve_static_assets = true

sidekiq 설정

$> vi sidekiq.yml
---
:pidfile: tmp/pids/sidekiq.pid
staging:
:concurrency: 10
production:
:concurrency: 20
development:
:concurrency: 10
:queues:
- [critical,4]
- [default, 2]
- [low]

production mode db생성

$> cd ~/discourse
$> RAILS_ENV=production bundle exec rake db:create db:migrate db:test:prepare

nil:class 에러가 나오던데 별 문제는 아니었던 것 같다.

관련 포스트가 meta.discourse.org 에 있었던 것 같으니 찾아보길 바란다.

sidekiq production mode 실행

$> bundle exec sidekiq -d -L log/sidekiq.log -C config/sidekiq.yml -e production

관리자 테스트 계정 생성

$> cd ~/discourse
$> cp db/api_test_seeds.rb db/seeds.rb
$> RAILS_ENV=production bundle exec rake db:seed
$> RAILS_ENV=production rails c
> u = User.last
> u.activate
> u.save
> quit

80포트로 실행하기 위해서는 root 권한이 필요한데 이때 postgresql 인증 문제가 발생한다.

postgresql 인증설정 변경이 필요하다. 하단 링크 참조

http://stackoverflow.com/questions/18664074/getting-error-peer-authentication-failed-for-user-postgres-when-trying-to-ge

postgresql 설정 변경

$> sudo /var/lib/pgsql/data/pg_hba.conf
local   all             postgres                                peer

Should be

local   all             postgres                                md5
$> sudo systemctl restart postgresql

에셋 빌드

$> RAILS_ENV=production bundle exec rake assets:precompile

thin 서버 실행

$> rvmsudo rails server thin -b 0.0.0.0 -p 80 -e production

 

 

 

[Ruby on Rails] install rails using mysql for ubuntu

환경 ubuntu 13.04
rvm 설치
ruby 2.0.0

gem install rdoc
gem install rails

— Mysql 설정(선행되어 있다면 무시) —

mysql 라이브러리 설치

sudo apt-get install ruby-mysql2 libmysqlclient-dev

mysql2 젬 설치

gem install mysql2

mysql 사용자 추가

  • localhost에서만 mysql 서버를 접속할 경우
create user 'username'@'localhost' identified by 'password';
grant all privileges on *.* to 'username'@'localhost';
  • 외부서버에서 mysql 서버에 접속할 경우
create user 'username'@'%' identified by 'password';
grant all privileges on *.* to 'username'@'%';

%로 호스트를 설정할 경우 모든 ip접속 허용을 뜻한다.

— Mysql 설정 끝 —

rails 로 테스트 프로젝트 blog 생성

rails new blog --database=mysql

젬 설치

bundle install

execjs 에러가 난다면,
blog/Gemfile 오픈후 하단에 아래 두줄 추가

gem 'execjs'
gem 'therubyracer'

blog/config/database.yml 오픈
필요없다면 blog_development 만 남기고 하단 주석 or 삭제

mysql user, password 입력

development:
  adapter: mysql2
  encoding: utf8
  database: blog_development
  pool: 5
  username: test_user
  password: test1234
  socket: /var/run/mysqld/mysqld.sock

빈 데이터베이스 생성

 rake db:create

rails 서버 실행

rails s

자세한 정보나 더 많은 정보를 원할 경우 하단 링크 참조
레일스 시작하기