【问题标题】:Can't display validation errors with best_in_place gem无法使用 best_in_place gem 显示验证错误
【发布时间】:2011-08-21 09:49:49
【问题描述】:

我在 Rails 3.0.9 中使用 best_in_place gem。好像我有一切工作。我按照安装说明进行操作,然后可以单击一个项目,对其进行编辑并使用 ajax 将所有内容保存在一个位置。

但是,当测试验证功能但输入虚假数据时,不会显示错误消息。

我不确定这是否应该通过 javascript 神奇地完成,或者我是否应该提供某种 div 标签或可以显示错误消息的东西。

在萤火虫中检查这个,我得到了正确的 json 响应。就我而言,我可以看到

[“债务长度无效”]

但这不会在任何地方呈现。

我还需要在视图中添加什么来呈现验证错误吗?它应该通过 purr.js 显示。除了将javascript文件放在我的公共目录中之外,我是否需要做任何事情,在application.js中启动best_in_place并将

<p>
  <b>Debts:</b>
  <%= best_in_place @prospect, :debts, :type => :input %>
</p>

在视图中?

【问题讨论】:

  • 似乎没有得到任何答案。想知道这是否是没有人有答案的情况,或者我的问题更可能不够清楚。欢迎对我应该提供的任何其他信息提出任何建议。
  • 你的控制器是什么样的?如果更新失败,你会打电话给 respond_with_bip 吗?

标签: ruby-on-rails-3 json gem


【解决方案1】:

您的问题听起来和我的一样:在Railscast #302 仔细检查,我注意到错误消息正在打印但在页面的左下方,很难看到并且容易错过。

列出该页面的purr CSS 代码将格式化并在网页上更清晰地显示。

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    您应该添加正确的控制器操作

    def update
      ..
      respond_to do |format|   
        format.json { render json: @prospect } 
      end
    end  
    

    或改用respond_with_bip 助手。并且不要忘记定义 .purr CSS 类,“Best In Place” gem 使用 jQuery Purr 插件来显示错误消息:

    .purr {
      position: fixed;
      top: 30px;
      right: 100px;
      width: 250px;
      padding: 20px;
      background-color: #FCC;
      border: solid 2px #C66;
      &:first-letter { text-transform: uppercase; }
    }
    

    【讨论】:

      【解决方案3】:

      保重。在 application.js 中添加 best_in_place.purr 插件而不是 jquery.purr。它对我有用。

      //= require jquery
      //= require jquery_ujs
      //= require bootstrap
      //= require best_in_place.purr
      //= require best_in_place
      //= require_tree .
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-01-25
        • 2012-04-11
        • 2012-12-07
        • 2016-10-13
        • 1970-01-01
        • 2012-01-19
        • 2019-01-30
        相关资源
        最近更新 更多