如何在rails中验证select_date

时间:2015-12-31 00:56:30

标签: ruby-on-rails ruby validation ruby-on-rails-4

在这里开始使用rails,我尝试允许用户访问我公司的网站,使用date_select输入他们的生日。 一切正常,直到我输入无效日期,如2月31日。它给了我一个argumentError说日期无效。 我想在没有为我的配置添加gem的情况下捕获错误,但它对我来说很模糊,我在过去两天尝试的所有内容都不起作用。

这是我的user.rb文件

validate :ensure_birth_date_valid, if: lambda { mentee? && born_on.present? }

def ensure_birth_date_valid
  Date.parse(born_on)   
rescue
  error.add(:born_on, :invalid)
end

这是表格

<% if registration_for?(:mentee) %>
  <div class="lobbyForm-group">
    <%= f.label :born_on, class: 'lobbyForm-label' %>
    <%= f.date_select :born_on, { :start_year => Date.today.year - Application::MENTEE_AGE_RANGE_MIN, :end_year => Date.today.year - Application::MENTEE_AGE_RANGE_MAX, :order => [:day, :month, :year], :prompt => true}, {:class => 'lobbyForm-control w-auto'} %>
  </div>
<% end %>

以下是将date_select转换为日期的代码

def user_params
  if params[:user]['born_on(1i)'].present? && params[:user]['born_on(2i)'].present? && params[:user]['born_on(3i)'].present?
    date = Date.new params[:user]['born_on(1i)'].to_i, params[:user]['born_on(2i)'].to_i, params[:user]['born_on(3i)'].to_i
    params[:user][:born_on] = date
  end

  permitted_params = [:first_name, :last_name, :email, :password, :password_confirmation, :born_on, :marketing_communications_accepted]
  params.require(:user).permit(*permitted_params)

  params[:user].merge mentee: true
end

这是完整的堆栈跟踪错误

/work/academos/academos-plateforme-web/app/controllers/lobby/mentee_registrations_controller.rb:36:in `new'
/work/academos/academos-plateforme-web/app/controllers/lobby/mentee_registrations_controller.rb:36:in `user_params'
/work/academos/academos-plateforme-web/app/controllers/lobby/registrations_controller.rb:25:in `create'
/work/academos/academos-plateforme-web/app/controllers/lobby/mentee_registrations_controller.rb:12:in `create'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/abstract_controller/base.rb:189:in `process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal/rendering.rb:10:in `process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/callbacks.rb:113:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/callbacks.rb:113:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/callbacks.rb:552:in `block (2 levels) in compile'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/callbacks.rb:502:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/callbacks.rb:502:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/callbacks.rb:86:in `run_callbacks'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/abstract_controller/callbacks.rb:19:in `process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal/rescue.rb:29:in `process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/notifications.rb:159:in `block in instrument'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/notifications.rb:159:in `instrument'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.1.11/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/abstract_controller/base.rb:136:in `process'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionview-4.1.11/lib/action_view/rendering.rb:30:in `process'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal.rb:196:in `dispatch'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal.rb:232:in `block in action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/routing/route_set.rb:82:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/routing/route_set.rb:50:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/journey/router.rb:73:in `block in call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/journey/router.rb:59:in `each'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/journey/router.rb:59:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/routing/route_set.rb:692:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/omniauth-1.2.1/lib/omniauth/strategy.rb:186:in `call!'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/omniauth-1.2.1/lib/omniauth/strategy.rb:164:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/omniauth-1.2.1/lib/omniauth/strategy.rb:186:in `call!'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/omniauth-1.2.1/lib/omniauth/strategy.rb:164:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bullet-4.8.0/lib/bullet/rack.rb:10:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/rack/error_collector.rb:50:in `traced_call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/rack/agent_hooks.rb:26:in `traced_call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/rack/browser_monitoring.rb:23:in `traced_call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/rack/developer_mode.rb:48:in `traced_call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/etag.rb:23:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/conditionalget.rb:35:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/head.rb:11:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/remotipart-1.2.1/lib/remotipart/middleware.rb:27:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/flash.rb:254:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/session/abstract/id.rb:225:in `context'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/session/abstract/id.rb:220:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/cookies.rb:562:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.1.11/lib/active_record/query_cache.rb:36:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.1.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.1.11/lib/active_record/migration.rb:380:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/callbacks.rb:82:in `run_callbacks'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/reloader.rb:73:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.1.11/lib/rails/rack/logger.rb:38:in `call_app'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.1.11/lib/rails/rack/logger.rb:22:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/request_id.rb:21:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/methodoverride.rb:21:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/runtime.rb:17:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/lock.rb:17:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/static.rb:84:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/sendfile.rb:112:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sentry-raven-0.13.3/lib/raven/integrations/rack.rb:54:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.1.11/lib/rails/engine.rb:514:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.1.11/lib/rails/application.rb:144:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.10.2/lib/puma/rack_patch.rb:13:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.10.2/lib/puma/configuration.rb:74:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.10.2/lib/puma/server.rb:492:in `handle_request'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.10.2/lib/puma/server.rb:363:in `process_client'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.10.2/lib/puma/server.rb:254:in `block in run'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.10.2/lib/puma/thread_pool.rb:101:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.10.2/lib/puma/thread_pool.rb:101:in `block in spawn_thread'

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

好的,我明白了。这是有问题的部分:

date = Date.new params[:user]['born_on(1i)'].to_i, params[:user]['born_on(2i)'].to_i, params[:user]['born_on(3i)'].to_i
    params[:user][:born_on] = date

你不应该在控制器中调用Date.new。

您可以在

行中执行某些操作
date = "#{params[:user]['born_on(1i)'].to_i}-#{params[:user]['born_on(2i)'].to_i}-#{params[:user]['born_on(3i)'].to_i}"
params[:user][:born_on] = date

现在您将拥有Date.parse(&#39; 2016-02-31&#39;)并且可以添加错误。