2

我在客户端验证中收到“没有将 Fixnum 隐式转换为字符串”的错误。在 SO 上找不到任何关于此的内容。代码如下:

视图中的表格:

<% @tournament.sub_tournaments.each_with_index do |sub, i| %>
  <%= f.fields_for :sub_tournaments, sub, :validate => true do |sub_form| %>
    <div class="tab-content match-content hide">
      <span class="match_fields"></span>
      <fieldset class="emty">     
        <legend>Match</legend>
        <div class="add-item add_match">
      <% if i == 1 %>
        <%= link_to_add_matches_fields(sub_form, :player_matches, i) %>
      <% else %>
        <%= link_to_add_matches_fields(sub_form, :team_matches, i) %>
      <% end %>
        </div>
      </fieldset>                    
    </div>  
  <% end %>
<% end %>  

中的视图link_to_add_matches_fields引用application_helper

def link_to_add_matches_fields(f, association, index)
  new_object = f.object.send(association).klass.new
  id = new_object.object_id
  game = Game.find(index + 1)
  fields = f.fields_for(association, new_object, child_index: id) do |builder|
    render("tournaments/form_partials/" + association.to_s.singularize + "_fields", f: builder, game: game)
  end
  link_to('#', :class => "add-matches-button", data: {id: id, fields: fields.gsub("\n", "")}) do
    '<span class="sign pos">+</span><div>ADD Match</div>'.html_safe
  end
end  

一切都在这里工作并传递给_team_matches_player_matches正确传递。但是在_team_matches——

<fieldset>
  <%= f.hidden_field :_destroy %>
  <legend>Match<span class="remove">Remove</span></legend>
  <table> 
    <tr> 
      <td> HOME TEAM
##this line##  <%= f.collection_select(:home_team_id, TeamDivision.where("game_id = ?", game.id), :id, :name, {include_blank: true}) %>
      </td>
      ...

标记的行抛出错误 - 如果我取出 collection_select 并放入另一个变量,或者只是文本,则一切正常。如果更改TeamDivision.where零件,则会引发相同的错误。根据完整的跟踪(如下),它与客户端验证有关,但不确定是什么阻止了表单的显示......?

TypeError - no implicit conversion of Fixnum into String:
  client_side_validations (3.2.5) lib/client_side_validations/action_view/form_builder.rb:98:in `build_validation_options'
  client_side_validations (3.2.5) lib/client_side_validations/action_view/form_builder.rb:75:in `collection_select_with_client_side_validations'
  app/views/tournaments/form_partials/_team_match_fields.html.erb:7:in `_app_views_tournaments_form_partials__team_match_fields_html_erb___1390226928296495378_2640008440'
  actionpack (3.2.13) lib/action_view/template.rb:145:in `block in render'
  activesupport (3.2.13) lib/active_support/notifications.rb:125:in `instrument'
  actionpack (3.2.13) lib/action_view/template.rb:143:in `render'
  rack-mini-profiler (0.1.26) Ruby/lib/mini_profiler/profiling_methods.rb:90:in `block in profile_method'
  actionpack (3.2.13) lib/action_view/renderer/partial_renderer.rb:265:in `render_partial'
  actionpack (3.2.13) lib/action_view/renderer/partial_renderer.rb:238:in `block in render'
  actionpack (3.2.13) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
  activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument'
  activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument'
  actionpack (3.2.13) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
  actionpack (3.2.13) lib/action_view/renderer/partial_renderer.rb:237:in `render'
  actionpack (3.2.13) lib/action_view/renderer/renderer.rb:41:in `render_partial'
  actionpack (3.2.13) lib/action_view/helpers/rendering_helper.rb:27:in `render'
  app/helpers/application_helper.rb:35:in `block in link_to_add_matches_fields'
  actionpack (3.2.13) lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
  actionpack (3.2.13) lib/action_view/helpers/capture_helper.rb:187:in `with_output_buffer'
  actionpack (3.2.13) lib/action_view/helpers/capture_helper.rb:40:in `capture'
  actionpack (3.2.13) lib/action_view/helpers/form_helper.rb:605:in `fields_for'
  client_side_validations (3.2.5) lib/client_side_validations/action_view/form_helper.rb:54:in `fields_for'
  actionpack (3.2.13) lib/action_view/helpers/form_helper.rb:1467:in `fields_for_nested_model'
  actionpack (3.2.13) lib/action_view/helpers/form_helper.rb:1453:in `block in fields_for_with_nested_attributes'
  actionpack (3.2.13) lib/action_view/helpers/form_helper.rb:1452:in `fields_for_with_nested_attributes'
  actionpack (3.2.13) lib/action_view/helpers/form_helper.rb:1302:in `fields_for'
  client_side_validations (3.2.5) lib/client_side_validations/action_view/form_builder.rb:53:in `fields_for_with_client_side_validations'
  app/helpers/application_helper.rb:34:in `link_to_add_matches_fields'
  app/views/tournaments/form_partials/_form.html.erb:172:in `block (3 levels) in _app_views_tournaments_form_partials__form_html_erb__2167663622248243032_2516373920'
  actionpack (3.2.13) lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
  actionpack (3.2.13) lib/action_view/helpers/capture_helper.rb:187:in `with_output_buffer'
  actionpack (3.2.13) lib/action_view/helpers/capture_helper.rb:40:in `capture'
  actionpack (3.2.13) lib/action_view/helpers/form_helper.rb:605:in `fields_for'
  client_side_validations (3.2.5) lib/client_side_validations/action_view/form_helper.rb:54:in `fields_for'
  actionpack (3.2.13) lib/action_view/helpers/form_helper.rb:1467:in `fields_for_nested_model'
  actionpack (3.2.13) lib/action_view/helpers/form_helper.rb:1453:in `block in fields_for_with_nested_attributes'
  actionpack (3.2.13) lib/action_view/helpers/form_helper.rb:1452:in `fields_for_with_nested_attributes'
  actionpack (3.2.13) lib/action_view/helpers/form_helper.rb:1302:in `fields_for'
  client_side_validations (3.2.5) lib/client_side_validations/action_view/form_builder.rb:53:in `fields_for_with_client_side_validations'
  app/views/tournaments/form_partials/_form.html.erb:163:in `block (2 levels) in _app_views_tournaments_form_partials__form_html_erb__2167663622248243032_2516373920'
  activerecord (3.2.13) lib/active_record/associations/collection_proxy.rb:89:in `method_missing'
  app/views/tournaments/form_partials/_form.html.erb:162:in `block in _app_views_tournaments_form_partials__form_html_erb__2167663622248243032_2516373920'
  actionpack (3.2.13) lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
  actionpack (3.2.13) lib/action_view/helpers/capture_helper.rb:187:in `with_output_buffer'
  actionpack (3.2.13) lib/action_view/helpers/capture_helper.rb:40:in `capture'
  actionpack (3.2.13) lib/action_view/helpers/form_helper.rb:378:in `form_for'
  client_side_validations (3.2.5) lib/client_side_validations/action_view/form_helper.rb:25:in `form_for'
  app/views/tournaments/form_partials/_form.html.erb:1:in `_app_views_tournaments_form_partials__form_html_erb__2167663622248243032_2516373920'
  actionpack (3.2.13) lib/action_view/template.rb:145:in `block in render'
  activesupport (3.2.13) lib/active_support/notifications.rb:125:in `instrument'
  actionpack (3.2.13) lib/action_view/template.rb:143:in `render'
  rack-mini-profiler (0.1.26) Ruby/lib/mini_profiler/profiling_methods.rb:90:in `block in profile_method'
  actionpack (3.2.13) lib/action_view/renderer/partial_renderer.rb:265:in `render_partial'
  actionpack (3.2.13) lib/action_view/renderer/partial_renderer.rb:238:in `block in render'
  actionpack (3.2.13) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
  activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument'
  activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument'
  actionpack (3.2.13) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
  actionpack (3.2.13) lib/action_view/renderer/partial_renderer.rb:237:in `render'
  actionpack (3.2.13) lib/action_view/renderer/renderer.rb:41:in `render_partial'
  actionpack (3.2.13) lib/action_view/helpers/rendering_helper.rb:27:in `render'
  app/views/tournaments/new.html.erb:7:in `_app_views_tournaments_new_html_erb___2830740236402949620_2540177140'
  actionpack (3.2.13) lib/action_view/template.rb:145:in `block in render'
  activesupport (3.2.13) lib/active_support/notifications.rb:125:in `instrument'
  actionpack (3.2.13) lib/action_view/template.rb:143:in `render'
  rack-mini-profiler (0.1.26) Ruby/lib/mini_profiler/profiling_methods.rb:90:in `block in profile_method'
  actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
  actionpack (3.2.13) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
  activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument'
  activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument'
  actionpack (3.2.13) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
  actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
  actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
  actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:45:in `render_template'
  actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:18:in `render'
  actionpack (3.2.13) lib/action_view/renderer/renderer.rb:36:in `render_template'
  actionpack (3.2.13) lib/action_view/renderer/renderer.rb:17:in `render'
  actionpack (3.2.13) lib/abstract_controller/rendering.rb:110:in `_render_template'
  actionpack (3.2.13) lib/action_controller/metal/streaming.rb:225:in `_render_template'
  actionpack (3.2.13) lib/abstract_controller/rendering.rb:103:in `render_to_body'
  actionpack (3.2.13) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
  actionpack (3.2.13) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
  actionpack (3.2.13) lib/abstract_controller/rendering.rb:88:in `render'
  actionpack (3.2.13) lib/action_controller/metal/rendering.rb:16:in `render'
  actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
  activesupport (3.2.13) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
  /Users/*/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
  activesupport (3.2.13) lib/active_support/core_ext/benchmark.rb:5:in `ms'
  actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
  actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
  activerecord (3.2.13) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
  actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:39:in `render'
  actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
  actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
  actionpack (3.2.13) lib/abstract_controller/base.rb:167:in `process_action'
  actionpack (3.2.13) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (3.2.13) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
  activesupport (3.2.13) lib/active_support/callbacks.rb:448:in `block in _run__4570382803702994908__process_action__2904075733109352235__callbacks'
  activesupport (3.2.13) lib/active_support/callbacks.rb:215:in `block in _conditional_callback_around_64511'
  app/controllers/application_controller.rb:19:in `set_time_zone'
  activesupport (3.2.13) lib/active_support/callbacks.rb:214:in `_conditional_callback_around_64511'
  activesupport (3.2.13) lib/active_support/callbacks.rb:414:in `_run__4570382803702994908__process_action__2904075733109352235__callbacks'
  activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
  activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.13) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (3.2.13) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
  activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument'
  activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument'
  actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
  actionpack (3.2.13) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
  activerecord (3.2.13) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (3.2.13) lib/abstract_controller/base.rb:121:in `process'
  actionpack (3.2.13) lib/abstract_controller/rendering.rb:45:in `process'
  rack-mini-profiler (0.1.26) Ruby/lib/mini_profiler/profiling_methods.rb:90:in `block in profile_method'
  actionpack (3.2.13) lib/action_controller/metal.rb:203:in `dispatch'
  actionpack (3.2.13) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
  actionpack (3.2.13) lib/action_controller/metal.rb:246:in `block in action'
  actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
  actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:36:in `call'
  journey (1.0.4) lib/journey/router.rb:68:in `block in call'
  journey (1.0.4) lib/journey/router.rb:56:in `call'
  actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:612:in `call'
  bullet (4.6.0) lib/bullet/rack.rb:10:in `call'
  client_side_validations (3.2.5) lib/client_side_validations/middleware.rb:21:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  rack (1.4.5) lib/rack/etag.rb:23:in `call'
  rack (1.4.5) lib/rack/conditionalget.rb:25:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/head.rb:14:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/flash.rb:242:in `call'
  rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
  rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/cookies.rb:341:in `call'
  activerecord (3.2.13) lib/active_record/query_cache.rb:64:in `call'
  activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `_run__3907649973208251614__call__26916800040981581__callbacks'
  activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/reloader.rb:65:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  better_errors (0.9.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (0.9.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (0.9.0) lib/better_errors/middleware.rb:56:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app'
  railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call'
  activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged'
  railties (3.2.13) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.5) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.5) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63:in `call'
  rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
  rack-cache (1.2) lib/rack/cache/context.rb:245:in `fetch'
  rack-cache (1.2) lib/rack/cache/context.rb:185:in `lookup'
  rack-cache (1.2) lib/rack/cache/context.rb:66:in `call!'
  rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
  rack-mini-profiler (0.1.26) Ruby/lib/mini_profiler/profiler.rb:278:in `call'
  railties (3.2.13) lib/rails/engine.rb:479:in `call'
  railties (3.2.13) lib/rails/application.rb:223:in `call'
  rack (1.4.5) lib/rack/content_length.rb:14:in `call'
  railties (3.2.13) lib/rails/rack/log_tailer.rb:17:in `call'
  rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
  /Users/*/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
  /Users/*/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
  /Users/*/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
4

1 回答 1

2

您必须更新客户端验证 gem。

请参阅此提交:https ://github.com/bcardarella/client_side_validations/commit/1602e5da3cf9535cf1254046aa8d8f1248fa5b58

变化:

child_index = @options[:child_index] ? "(\\d+|#{Regexp.escape(@options[:child_index])})" : "\\d+"
                                                                                   ^^^^
child_index = @options[:child_index] ? "(\\d+|#{Regexp.escape(@options[:child_index].to_s)})

跑:

bundle update --source client_side_validations
于 2013-10-24T16:21:39.413 回答