我正在尝试将 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)
有什么明显的我做错了吗?