我正在尝试在我正在运行的测试应用程序中使用 best_in_place gem。虽然 best_in_place gem 已安装并且在页面上加载时没有出现错误(iehtml 与 etc. 一起加载),但在通过 HTML 视图中的“输入”框修改用户参数后单击输入似乎存在问题。输入框中的用户输入似乎没有更新到我的数据库中。
我的观点 :
<%= best_in_place @user, :name %>
<%= best_in_place @user, :name, activator: "#edit_#{@user.id}", display_with: :link_to,
helper_options: user_path(@user) %>
<small><a href="#" id="edit_<%= @user.id %>">edit</a></small>
我的用户控制器:
def edit
@user = User.find(params[:id])
end
def update
@user = User.find params[:id]
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to(@user, :notice => 'User was successfully updated.') }
format.json { respond_with_bip(@user) }
else
format.html { render :action => "edit" }
format.json { respond_with_bip(@user) }
end
end
end
尝试在服务器上运行时的终端输出脚本
Started PUT "/users/108" for 127.0.0.1 at 2013-09-24 15:26:14 +0530
Processing by UsersController#update as JSON
Parameters: {"user"=>{"name"=>"ap"}, "authenticity_token"=>"3d/ZtW3csCIqXWG5Qk1U2QjMlyTQZ5W9/tBnVNZlHY8=", "id"=>"108"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = 'VJ-EiGLCCGtqjPhuebTbZQ' LIMIT 1
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", "108"]]
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", "108"]]
(0.1ms) begin transaction
User Exists (1.0ms) SELECT 1 AS one FROM "users" WHERE (LOWER("users"."email") = LOWER('b@b.com') AND "users"."id" != 108) LIMIT 1
(0.1ms) rollback transaction
Completed 422 Unprocessable Entity in 347ms (Views: 0.4ms | ActiveRecord: 1.7ms)
理想情况下,我期望在上面代码中的开始事务之后有一个 UPDATE "users" SET ........ 语句。你知道为什么我的代码在这种情况下不更新用户参数吗?