best_in_place gem,rails4不显示错误

时间:2013-11-11 21:49:50

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

我正在尝试使用带有Rails 4应用程序的best_in_place gem。我可以 让它更新有效的编辑到一个字段,但如果我输入 无效的值,我没有看到错误消息。我添加了.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)

有什么事情显而易见我做错了吗?

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题。我的解决方案是在application.js中包含所有这三行:

//= require best_in_place
//= require best_in_place.purr
//= require jquery.purr

如果省略了jquery.purr或best_in_place.purr,则不会向用户显示任何错误消息。

答案 1 :(得分:0)

有关记录,请参阅上面的评论:除了best_in_place.js之外,我的javascript资产中没有包括best_in_place.purr.js。

希望它可以帮助别人忽视这一点。

我认为这回答了。

相关问题