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를 넣어서 해결했습니다.

Rails spec + sidekiq 설정

Rails spec + sidekiq 설정

Rails 에서 rspecsidekiq를 사용 하는 중에 local machine 에서는 별 문제가 없었는데, Drone · Continuous Deliver에서 test 기능을 사용하는 중에 문제가 생겼습니다.

문제점

drone 에서 rspec 실행시 error 발생

`localhost:6379` connection error

해결

찾아보니 rspec 실행시 sidekiq에서 redis 접속을 시도하는 문제였습니다.

참고: Testing · mperham/sidekiq Wiki · GitHub

위 내용을 참고해서 rspec/rails_helper.rb 에 아래 두줄을 추가했습니다.

require 'sidekiq/testing'
Sidekiq::Testing.fake!

이제 정상적으로 rspecdrone 에서 동작하는 것을 확인 할 수 있습니다.

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 때문에 시간이 소모되는 문제를 쉽게 해결 가능합니다.

Rails 5 lib folder 로딩이 안되는 문제

Rails 5 ‘lib’ folder autoload failure

Rails 5 에서 lib 폴더를 autoload path에 포함시키고 싶은데 아래 코드가 제대로 동작을 하지 않았습니다.

config.autoload_paths << Rails.root.join('lib')

첫 번째 방법

찾아보니 스택오버플로우에 아래와 같은 정보가 있습니다.

autoload – Rails 5: Load lib files in production – Stack Overflow

코드를 보면 initializer를 이용해서 rb 파일들을 읽어오도록 구현되어 있습니다.

이런식으로 원하는 코드들만 가져와도 될 듯합니다. 스타도 많이 받았습니다. ㅎㅎㅎㅎ

두번째 방법

Rails falls back on non-thread-safe autoloading even when eager_load is true · Issue #13142 · rails/rails · GitHub

위의 글을 보면 이 아저씨가 해결한 방법은 autoload 를 사용하지 않고 eager_load 를 사용하라고 합니다.

config/environments/production.rb 의 내용을 봅니다.

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both threaded web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.
  config.eager_load = true

eager_load 가 기본 설정입니다.

config/application.rb 하단에 아래 내용을 추가합니다.

config.eager_load_paths << Rails.root.join('lib')

문제 없이 잘 동작합니다.

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 rbenv install 2.0.0-p247 fail for Centos

rbenv 를 이용해서 ruby 2.0.0 p247을 설치할 때 에러가 발생한다. centos 6.5에서 발생했다.

해결법을 기록해둔다. 참고가 되길 바란다.

ref web site

rbenv install 2.0.0-p247

위의 명령을 실행했을 때 아래 상황 발생

problem:

BUILD FAILED

Inspect or clean up the working tree at /tmp/ruby-build.20150424111036.5089
Results logged to /tmp/ruby-build.20150424111036.5089.log

Last 10 log lines:
ossl_pkey_ec.c:821: error: for each function it appears in.)
make[2]: *** [ossl_pkey_ec.o] Error 1
make[2]: Leaving directory `/tmp/ruby-build.20150424111036.5089/ruby-2.0.0-p247/ext/openssl'
make[1]: *** [ext/openssl/all] Error 2
make[1]: *** Waiting for unfinished jobs....
installing default callback libraries
linking shared-object dl/callback.so
make[2]: Leaving directory `/tmp/ruby-build.20150424111036.5089/ruby-2.0.0-p247/ext/dl/callback'
make[1]: Leaving directory `/tmp/ruby-build.20150424111036.5089/ruby-2.0.0-p247'
make: *** [build-ext] Error 2

solution:

1. Create “patch.diff” file.
2. Copy the content below.

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41807)
+++ ChangeLog	(revision 41808)
@@ -1,3 +1,16 @@
+Sat Jul  6 07:37:43 2013  Martin Bosslet  <Martin.Bosslet@gmail.com>
+
+	* ext/openssl/ossl_pkey_ec.c: Ensure compatibility to builds of
+	  OpenSSL with OPENSSL_NO_EC2M defined, but OPENSSL_NO_EC not
+	  defined.
+	* test/openssl/test_pkey_ec.rb: Iterate over built-in curves
+	  (and assert their non-emptiness!) instead of hard-coding them, as
+	  this may cause problems with respect to the different availability
+	  of individual curves in individual OpenSSL builds.
+	  [ruby-core:54881] [Bug #8384]
+
+	  Thanks to Vit Ondruch for providing the patch!
+
 Sat Jul  6 07:12:39 2013  Martin Bosslet  <Martin.Bosslet@gmail.com>
 
 	* test/openssl/test_x509crl.rb: Remove unused variable.
Index: ext/openssl/ossl_pkey_ec.c
===================================================================
--- ext/openssl/ossl_pkey_ec.c	(revision 41807)
+++ ext/openssl/ossl_pkey_ec.c	(revision 41808)
@@ -762,8 +762,10 @@
                 method = EC_GFp_mont_method();
             } else if (id == s_GFp_nist) {
                 method = EC_GFp_nist_method();
+#if !defined(OPENSSL_NO_EC2M)
             } else if (id == s_GF2m_simple) {
                 method = EC_GF2m_simple_method();
+#endif
             }
 
             if (method) {
@@ -817,8 +819,10 @@
 
             if (id == s_GFp) {
                 new_curve = EC_GROUP_new_curve_GFp;
+#if !defined(OPENSSL_NO_EC2M)
             } else if (id == s_GF2m) {
                 new_curve = EC_GROUP_new_curve_GF2m;
+#endif
             } else {
                 ossl_raise(rb_eArgError, "unknown symbol, must be :GFp or :GF2m");
             }
Index: test/openssl/test_pkey_ec.rb
===================================================================
--- test/openssl/test_pkey_ec.rb	(revision 41807)
+++ test/openssl/test_pkey_ec.rb	(revision 41808)
@@ -7,28 +7,28 @@
     @data1 = 'foo'
     @data2 = 'bar' * 1000 # data too long for DSA sig
 
-    @group1 = OpenSSL::PKey::EC::Group.new('secp112r1')
-    @group2 = OpenSSL::PKey::EC::Group.new('sect163k1')
-    @group3 = OpenSSL::PKey::EC::Group.new('prime256v1')
+    @groups = []
+    @keys = []
 
-    @key1 = OpenSSL::PKey::EC.new
-    @key1.group = @group1
-    @key1.generate_key
+    OpenSSL::PKey::EC.builtin_curves.each do |curve, comment|
+      group = OpenSSL::PKey::EC::Group.new(curve)
 
-    @key2 = OpenSSL::PKey::EC.new(@group2.curve_name)
-    @key2.generate_key
+      key = OpenSSL::PKey::EC.new(group)
+      key.generate_key
 
-    @key3 = OpenSSL::PKey::EC.new(@group3)
-    @key3.generate_key
-
-    @groups = [@group1, @group2, @group3]
-    @keys = [@key1, @key2, @key3]
+      @groups << group
+      @keys << key
+    end
   end
 
   def compare_keys(k1, k2)
     assert_equal(k1.to_pem, k2.to_pem)
   end
 
+  def test_builtin_curves
+    assert(!OpenSSL::PKey::EC.builtin_curves.empty?)
+  end
+
   def test_curve_names
     @groups.each_with_index do |group, idx|
       key = @keys[idx]

3. Create “fedora.configure” file
4. Copy the content below.

#!/bin/sh
patch -p0 -i /tmp/patch.diff
exec ./configure "$@"

5. Execute this command.

RUBY_CONFIGURE=/home/user/fedora-configure rbenv install 2.0.0-p247

6. check ruby version.

rbenv versions

RVM install for multi user

How to install RVM for multi user.

RVM 설치하기
참고:

다중사용자 설정

sudo curl -sSL https://get.rvm.io | sudo bash -s stable

아래 내용처럼 나올 경우

Downloading https://github.com/rvm/rvm/archive/1.26.11.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.26.11/1.26.11.tar.gz.                                    asc
gpg: Signature made Tue 31 Mar 2015 06:52:13 AM KST using RSA key ID BF04FF17
gpg: Can't check signature: No public key
Warning, RVM 1.26.0 introduces signed releases and automated check of signatures                                     when GPG software found.
Assuming you trust Michal Papis import the mpapis public key (downloading the si                                    gnatures).

GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.26.11.tgz'                                     - 'https://github.com/rvm/rvm/releases/download/1.26.11/1.26.11.tar.gz.asc'!
try downloading the signatures:

    sudo gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A170                                    3113804BB82D39DC0E3

or if it fails:

    command curl -sSL https://rvm.io/mpapis.asc | sudo gpg2 --import -

the key can be compared with:

    https://rvm.io/mpapis.asc
    https://keybase.io/mpapis

공개키가 없다고 하니 공개키를 받아줘야할 듯.
콘솔 창에 나온데로 실행한다.

sudo gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

그리고 다시 첫번째 명령 실행

rvm이 잘 설치되었는지 아래 명령을 통해 확인한다.

type rvm | head -n 1

rvm is a function
이라고 나오면 정상

rvm을 사용할 계정을 rvm group에 포함시킨다.

sudo vi /etc/group

...

rvm:x:505:user,user2,user3

이제 rvm을 사용할 계정으로 다시 로그인 한다.
로그인을 다시 하는 이유는 rvm이 로그인 시간정보를 가지고 유효한 유저인지 판별하기 때문인 듯 하다. 공식사이트에서 확인해보시길.

설치 가능 목록 확인

rvm list known

2.0.0 설치

rvm install 2.0.0

여러 유저가 사용하므로 ruby에서 참조하는 gem을 다르게 할 수 있다.

rvm use 2.0.0@newgemset --create --default

newgemset 이라는 gem set을 만들어서 기본으로 사용하라는 명령이다. 이름은 마음대로 바꾸자.

[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

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

[ruby] rvm 설치하기 (단일 사용자 설정)

How to install RVM for Single user.

단일 사용자 설정

root 유저가 아닌 일반 계정으로 Ruby RVM 설치하기!

bash < <(curl -L https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
source .bash_profile
type rvm | head -1

성공시: rvm is a function

설치 가능한 목록

rvm list known
rvm install 2.0.0