【发布时间】:2013-11-11 21:49:50
【问题描述】:
我正在尝试将 best_in_place gem 与 Rails 4 应用程序一起使用。我可以 让它更新对字段的有效编辑,但如果我输入 无效值,我没有看到错误消息。我添加了 .purr 样式规则,但仍然没有乐趣。
我在控制器中使用以下内容:
def update
@transact = Transact.find(params[:id])
respond_to do |format|
if @transact.update_attributes(transact_params)
flash[:notice] = 'Transaction was successfully updated.'
format.html { redirect_to(@transact) }
format.xml { head :ok }
format.json { respond_with_bip(@transact) }
else
@errors = @transact.errors
format.html { render :action => "edit" }
format.xml { render :xml => @transact.errors, :status => :unprocessable_entity }
# format.json {
# render :json => @errors.full_messages,
# :status => :unprocessable_entity
# }
format.json { respond_with_bip(@transact) }
end
end
end
我也试过上面注释掉的代码,结果相似。
这是服务器对无效值的响应:
Processing by TransactsController#update as JSON
Parameters: {"transact"=>{"shares"=>"6741433.0x"}, "authenticity_token"=>"e+1ZEhVYuEMDURf81Kcxg0Ld28BfY60rRFRSZUq8RsY=", "id"=>"144314"}
Transact Load (0.5ms) SELECT "transacts".* FROM "transacts" WHERE "transacts"."id" = $1 LIMIT 1 [["id", "144314"]]
(0.1ms) BEGIN
(0.3ms) ROLLBACK
Completed 422 Unprocessable Entity in 60ms (Views: 0.2ms | ActiveRecord: 0.9ms)
有什么明显的我做错了吗?
【问题讨论】:
-
回答:除了 best_in_place.js 之外,我的 javascript 资产中没有包含 best_in_place.purr.js。
标签: ruby ruby-on-rails-4 best-in-place