【问题标题】:best_in_place gem with rails4 not displaying errors带有rails4的best_in_place gem不显示错误
【发布时间】: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


【解决方案1】:

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

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

如果 jquery.purr 或 best_in_place.purr 被忽略,则不会向用户显示错误消息。

【讨论】:

    【解决方案2】:

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

    希望它可以帮助其他人忽略这一点。

    我认为这已经回答了。

    【讨论】:

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