Rails 5.1 部分中的参数数量错误(给定 3,预期为 1..2)

诺泰克

我正在构建一个简单的 wiki 应用程序,并尝试将对象和索引/枚举传递给部分对象,因此当单击按钮时会弹出一个模式,我可以编辑用户。这是我的索引视图代码:

<table class="table table-striped">
  <thead>
    <th>Name</th>
    <th>Email</th>
    <th>Role</th>
    <th>Action</th>
  </thead>
  <tbody>
    <% @users.each_with_index do |u, index| %>
    <tr>
      <td><%= u.full_name %></td>
      <td><%= u.email %></td>
      <td><%= u.role %></td>
      <td><%= link_to "Modify", '#edit-user-modal', data: {toggle: "modal", target: "#edit-user-modal#{index}" }, class: 'btn btn-sm btn-success' %></td>
      <%= render 'edit_user_modal', u: u, index: index %>
     <% end %>
    </tr>
  </tbody>
</table>

这是我的模态代码:

<div id="edit-user-modal<%= index %>" class="modal fade new-user-modal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
  <div class="modal-dialog modal-sm" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
        <h4 class="modal-title" id="mySmallModalLabel">Modify User</h4>
      </div>
      <div class="modal-body">
        <%= form_for(u, url: '/user_admin', method: 'patch') do |f| %>
          <div class="form-group">
            <%= f.label :full_name, class: 'control-label' %>
            <%= f.text_field :full_name, class: "form-control" %>
            <%= f.label :email, class: 'control-label' %>
            <%= f.text_field :email, class: "form-control" %>
            <%= f.label :password, "Enter existing or New Password", class: 'control-label' %>
            <%= f.password_field :password, "Enter existing or New Password Confirmation", class: "form-control" %>
            <%= f.label :password_confirmation, class: 'control-label' %>
            <%= f.password_field :password_confirmation, class: "form-control" %>
            <%= f.label :role, class: 'control-label' %>
            <%= f.text_field :role, class: "form-control" %>
          </div>
          <div class="form-group">
            <%= f.submit "Create Users", class: "btn btn-primary" %>
          </div>
        <% end %>
      </div>
    </div>
  </div>
</div>

我以前设置过这样的东西,并且像这样传递当地人没有问题,但在这种特殊情况下,错误会在 wrong number of arguments (given 3, expected 1..2)

我之前使用过相同的策略来部分传递当地人并且没有问题。但由于某种原因,我收到此错误。

注意我使用的是 Rails 5.1 和 Ruby 2.4.0

更新堆栈跟踪

ActionView::Template::Error - wrong number of arguments (given 3, expected 1..2):
  actionview (5.1.1) lib/action_view/template/error.rb:67:in `initialize'
  actionview (5.1.1) lib/action_view/template.rb:321:in `handle_render_error'
  actionview (5.1.1) lib/action_view/template.rb:160:in `rescue in render'
  actionview (5.1.1) lib/action_view/template.rb:155:in `render'
  actionview (5.1.1) lib/action_view/renderer/partial_renderer.rb:342:in `block in render_partial'
  actionview (5.1.1) lib/action_view/renderer/abstract_renderer.rb:42:in `block in instrument'
  activesupport (5.1.1) lib/active_support/notifications.rb:166:in `block in instrument'
  activesupport (5.1.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
  activesupport (5.1.1) lib/active_support/notifications.rb:166:in `instrument'
  actionview (5.1.1) lib/action_view/renderer/abstract_renderer.rb:41:in `instrument'
  actionview (5.1.1) lib/action_view/renderer/partial_renderer.rb:331:in `render_partial'
  actionview (5.1.1) lib/action_view/renderer/partial_renderer.rb:310:in `render'
  actionview (5.1.1) lib/action_view/renderer/renderer.rb:47:in `render_partial'
  actionview (5.1.1) lib/action_view/helpers/rendering_helper.rb:35:in `render'
  app/views/user_admin/index.html.erb:12:in `block in _app_views_user_admin_index_html_erb__1902393957041503973_70195080307960'
  activerecord (5.1.1) lib/active_record/relation/delegation.rb:41:in `each'
  app/views/user_admin/index.html.erb:11:in `_app_views_user_admin_index_html_erb__1902393957041503973_70195080307960'
  actionview (5.1.1) lib/action_view/template.rb:157:in `block in render'
  activesupport (5.1.1) lib/active_support/notifications.rb:168:in `instrument'
  actionview (5.1.1) lib/action_view/template.rb:352:in `instrument_render_template'
  actionview (5.1.1) lib/action_view/template.rb:155:in `render'
  actionview (5.1.1) lib/action_view/renderer/template_renderer.rb:52:in `block (2 levels) in render_template'
  actionview (5.1.1) lib/action_view/renderer/abstract_renderer.rb:42:in `block in instrument'
  activesupport (5.1.1) lib/active_support/notifications.rb:166:in `block in instrument'
  activesupport (5.1.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
  activesupport (5.1.1) lib/active_support/notifications.rb:166:in `instrument'
  actionview (5.1.1) lib/action_view/renderer/abstract_renderer.rb:41:in `instrument'
  actionview (5.1.1) lib/action_view/renderer/template_renderer.rb:51:in `block in render_template'
  actionview (5.1.1) lib/action_view/renderer/template_renderer.rb:59:in `render_with_layout'
  actionview (5.1.1) lib/action_view/renderer/template_renderer.rb:50:in `render_template'
  actionview (5.1.1) lib/action_view/renderer/template_renderer.rb:14:in `render'
  actionview (5.1.1) lib/action_view/renderer/renderer.rb:42:in `render_template'
  actionview (5.1.1) lib/action_view/renderer/renderer.rb:23:in `render'
  actionview (5.1.1) lib/action_view/rendering.rb:103:in `_render_template'
  actionpack (5.1.1) lib/action_controller/metal/streaming.rb:217:in `_render_template'
  actionview (5.1.1) lib/action_view/rendering.rb:83:in `render_to_body'
  actionpack (5.1.1) lib/action_controller/metal/rendering.rb:52:in `render_to_body'
  actionpack (5.1.1) lib/action_controller/metal/renderers.rb:141:in `render_to_body'
  actionpack (5.1.1) lib/abstract_controller/rendering.rb:24:in `render'
  actionpack (5.1.1) lib/action_controller/metal/rendering.rb:36:in `render'
  actionpack (5.1.1) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
  activesupport (5.1.1) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
  /Users/nynhex/.rbenv/versions/2.4.0/lib/ruby/2.4.0/benchmark.rb:308:in `realtime'
  activesupport (5.1.1) lib/active_support/core_ext/benchmark.rb:12:in `ms'
  actionpack (5.1.1) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
  actionpack (5.1.1) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
  activerecord (5.1.1) lib/active_record/railties/controller_runtime.rb:29:in `cleanup_view_runtime'
  actionpack (5.1.1) lib/action_controller/metal/instrumentation.rb:43:in `render'
  actionpack (5.1.1) lib/action_controller/metal/implicit_render.rb:33:in `default_render'
  actionpack (5.1.1) lib/action_controller/metal/basic_implicit_render.rb:4:in `block in send_action'
  actionpack (5.1.1) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
  actionpack (5.1.1) lib/abstract_controller/base.rb:186:in `process_action'
  actionpack (5.1.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
  actionpack (5.1.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (5.1.1) lib/active_support/callbacks.rb:131:in `run_callbacks'
  actionpack (5.1.1) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (5.1.1) lib/action_controller/metal/rescue.rb:20:in `process_action'
  actionpack (5.1.1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (5.1.1) lib/active_support/notifications.rb:166:in `block in instrument'
  activesupport (5.1.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
  activesupport (5.1.1) lib/active_support/notifications.rb:166:in `instrument'
  actionpack (5.1.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (5.1.1) lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
  activerecord (5.1.1) lib/active_record/railties/controller_runtime.rb:22:in `process_action'
  actionpack (5.1.1) lib/abstract_controller/base.rb:124:in `process'
  actionview (5.1.1) lib/action_view/rendering.rb:30:in `process'
  actionpack (5.1.1) lib/action_controller/metal.rb:189:in `dispatch'
  actionpack (5.1.1) lib/action_controller/metal.rb:253:in `dispatch'
  actionpack (5.1.1) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
  actionpack (5.1.1) lib/action_dispatch/routing/route_set.rb:31:in `serve'
  actionpack (5.1.1) lib/action_dispatch/journey/router.rb:46:in `block in serve'
  actionpack (5.1.1) lib/action_dispatch/journey/router.rb:33:in `serve'
  actionpack (5.1.1) lib/action_dispatch/routing/route_set.rb:832:in `call'
  warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
  warden (1.2.7) lib/warden/manager.rb:35:in `call'
  rack (2.0.3) lib/rack/etag.rb:25:in `call'
  rack (2.0.3) lib/rack/conditional_get.rb:25:in `call'
  rack (2.0.3) lib/rack/head.rb:12:in `call'
  rack (2.0.3) lib/rack/session/abstract/id.rb:232:in `context'
  rack (2.0.3) lib/rack/session/abstract/id.rb:226:in `call'
  actionpack (5.1.1) lib/action_dispatch/middleware/cookies.rb:613:in `call'
  activerecord (5.1.1) lib/active_record/migration.rb:556:in `call'
  actionpack (5.1.1) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
  activesupport (5.1.1) lib/active_support/callbacks.rb:97:in `run_callbacks'
  actionpack (5.1.1) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
  actionpack (5.1.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
  actionpack (5.1.1) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
  web-console (3.5.1) lib/web_console/middleware.rb:135:in `call_app'
  web-console (3.5.1) lib/web_console/middleware.rb:28:in `block in call'
  web-console (3.5.1) lib/web_console/middleware.rb:18:in `call'
  actionpack (5.1.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
  railties (5.1.1) lib/rails/rack/logger.rb:36:in `call_app'
  railties (5.1.1) lib/rails/rack/logger.rb:24:in `block in call'
  activesupport (5.1.1) lib/active_support/tagged_logging.rb:69:in `block in tagged'
  activesupport (5.1.1) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (5.1.1) lib/active_support/tagged_logging.rb:69:in `tagged'
  railties (5.1.1) lib/rails/rack/logger.rb:24:in `call'
  sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call'
  actionpack (5.1.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
  actionpack (5.1.1) lib/action_dispatch/middleware/request_id.rb:25:in `call'
  rack (2.0.3) lib/rack/method_override.rb:22:in `call'
  rack (2.0.3) lib/rack/runtime.rb:22:in `call'
  activesupport (5.1.1) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
  actionpack (5.1.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
  actionpack (5.1.1) lib/action_dispatch/middleware/static.rb:125:in `call'
  rack (2.0.3) lib/rack/sendfile.rb:111:in `call'
  railties (5.1.1) lib/rails/engine.rb:522:in `call'
  puma (3.9.0) lib/puma/configuration.rb:224:in `call'
  puma (3.9.0) lib/puma/server.rb:602:in `handle_request'
  puma (3.9.0) lib/puma/server.rb:435:in `process_client'
  puma (3.9.0) lib/puma/server.rb:299:in `block in run'
  puma (3.9.0) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
凯西教务长

答案是部分:)

查看下面的行:

  <%= f.password_field :password, "Enter existing or New Password Confirmation", class: "form-control" %>

第二个参数是标签,似乎是上面一行中的一个简单的复制和粘贴错误。如果您删除该文本,一切都会好起来的。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Rails:参数数量错误(给定2个,预期为1个)MongoID

来自分类Dev

为什么在Rails中的搜索查询会出现错误“参数数量错误(给定1,预期为0)”?

来自分类Dev

Ruby on Rails:参数数量错误(给定 0,预期为 1)

来自分类Dev

发生 WebSocket 错误:参数数量错误(给定 2,预期为 1)

来自分类Dev

Rails:参数数目错误(给定1,预期为0)

来自分类Dev

ArgumentError异常:当我尝试上传图像时,参数数目错误(给定2个,预期为1个)(Rails 4; paperclip 5; paperclip-meta)

来自分类Dev

Jekyll:参数数量错误(给定2个,预期为1个)(ArgumentError)

来自分类Dev

ArgumentError:Update_Attribute 方法的参数数量错误(给定 1,预期为 2)

来自分类Dev

无法获取 Rails ActiveRecord:条件有效,“参数数量错误(给定 1,预期为 0)”

来自分类Dev

选民部分中的参数数量错误(0为1)

来自分类Dev

Docker运行产生错误``初始化'':错误的参数数量(给定2个,预期为1个)(ArgumentError)

来自分类Dev

fastlane 脚本中的参数数量错误(给定 0,预期为 1)(ArgumentError)

来自分类Dev

生成的RSpec控制器测试失败,参数数量错误(给定2个,预期为1个)

来自分类Dev

Rails ActiveCampaign gem-错误的参数数量(2为1)

来自分类Dev

Ruby on Rails和Mongomapper:错误的参数数量(2对1)

来自分类Dev

创建用户提交表单时,Ruby on Rails 4中的参数数量错误(0为1)

来自分类Dev

错误的参数数量(2为1)RoR错误

来自分类Dev

最小测试错误-ArgumentError:参数数量错误(给定1,预期为0)

来自分类Dev

最喜欢的操作出现错误:参数数量错误(给定1,预期为0)?

来自分类Dev

M.Hartl的Rails教程7.4.1中的参数数目错误(2为1)错误

来自分类Dev

Active Record Destroy ArgumentError(错误的参数数量(给定1,预期为0)):

来自分类Dev

ActiveRecord.find错误的参数数量2为1

来自分类Dev

Ruby:错误:当我给出正确数量的参数时,参数数量错误(给定 1,预期为 0)

来自分类Dev

rails 4-错误的参数数量(2为1)-stylesheet_link_tag和javascript_include_tag

来自分类Dev

Geocoder和Rails-错误的参数数量(1为3)

来自分类Dev

#<ArgumentError:错误的参数数量(1为2)>在admin.rb:32:in'kick'中

来自分类Dev

控制器中错误的参数数量(1对2)

来自分类Dev

Rails:UsersController#中的ArgumentError创建错误数量的参数(2为1)

来自分类Dev

错误的参数数量(1表示2)

Related 相关文章

  1. 1

    Rails:参数数量错误(给定2个,预期为1个)MongoID

  2. 2

    为什么在Rails中的搜索查询会出现错误“参数数量错误(给定1,预期为0)”?

  3. 3

    Ruby on Rails:参数数量错误(给定 0,预期为 1)

  4. 4

    发生 WebSocket 错误:参数数量错误(给定 2,预期为 1)

  5. 5

    Rails:参数数目错误(给定1,预期为0)

  6. 6

    ArgumentError异常:当我尝试上传图像时,参数数目错误(给定2个,预期为1个)(Rails 4; paperclip 5; paperclip-meta)

  7. 7

    Jekyll:参数数量错误(给定2个,预期为1个)(ArgumentError)

  8. 8

    ArgumentError:Update_Attribute 方法的参数数量错误(给定 1,预期为 2)

  9. 9

    无法获取 Rails ActiveRecord:条件有效,“参数数量错误(给定 1,预期为 0)”

  10. 10

    选民部分中的参数数量错误(0为1)

  11. 11

    Docker运行产生错误``初始化'':错误的参数数量(给定2个,预期为1个)(ArgumentError)

  12. 12

    fastlane 脚本中的参数数量错误(给定 0,预期为 1)(ArgumentError)

  13. 13

    生成的RSpec控制器测试失败,参数数量错误(给定2个,预期为1个)

  14. 14

    Rails ActiveCampaign gem-错误的参数数量(2为1)

  15. 15

    Ruby on Rails和Mongomapper:错误的参数数量(2对1)

  16. 16

    创建用户提交表单时,Ruby on Rails 4中的参数数量错误(0为1)

  17. 17

    错误的参数数量(2为1)RoR错误

  18. 18

    最小测试错误-ArgumentError:参数数量错误(给定1,预期为0)

  19. 19

    最喜欢的操作出现错误:参数数量错误(给定1,预期为0)?

  20. 20

    M.Hartl的Rails教程7.4.1中的参数数目错误(2为1)错误

  21. 21

    Active Record Destroy ArgumentError(错误的参数数量(给定1,预期为0)):

  22. 22

    ActiveRecord.find错误的参数数量2为1

  23. 23

    Ruby:错误:当我给出正确数量的参数时,参数数量错误(给定 1,预期为 0)

  24. 24

    rails 4-错误的参数数量(2为1)-stylesheet_link_tag和javascript_include_tag

  25. 25

    Geocoder和Rails-错误的参数数量(1为3)

  26. 26

    #<ArgumentError:错误的参数数量(1为2)>在admin.rb:32:in'kick'中

  27. 27

    控制器中错误的参数数量(1对2)

  28. 28

    Rails:UsersController#中的ArgumentError创建错误数量的参数(2为1)

  29. 29

    错误的参数数量(1表示2)

热门标签

归档