【问题标题】:Using the best_in_place gem within a table在表中使用 best_in_place gem
【发布时间】:2013-03-30 04:25:51
【问题描述】:

我有一张列出所有用户的表格。我不想打开每个用户然后进行编辑,而是想编辑该表中的某些字段。

- @users.each do |u|
  %tr
    %td= u.name
    %td= best_in_place u, :email_flag, :type => :checkbox

问题似乎是唯一传回的参数是复选框字段:

Processing by UsersController#update as
  Parameters: {"user"=>{"email_flag"=>"true"}

我是不是以错误的方式处理这个问题?为什么用户对象 'u' 没有被传回?

【问题讨论】:

标签: ruby-on-rails best-in-place


【解决方案1】:

best_in_place 在这里正常工作。不需要每次都传输您正在编辑的整个属性集。这就是 HTTP PUT(或 PATCH,取决于您的 Rails 版本)的用途——更新模型现有实例的属性。就像在 SQL 中一样,当你运行 UPDATE users SET email='something@example.com' WHERE id=1 时,你不必每次都列出每个字段。仅触摸指定的列。

如您在评论中所说,当您为 last_namecountry 添加另一个字段时,它的工作方式相同。

【讨论】:

    猜你喜欢
    • 2012-01-19
    • 2013-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-06
    • 2012-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多