在图片管理里添加了校验方法之后,发现在更新的时候页面不显示校验报错的信息

class Picture < ApplicationRecord
belongs_to :imageable, polymorphic: true validates_uniqueness_of :name, scope: [:imageable_id, :imageable_type]
end

update!在校验的时候会抛出异常,导致ajax操作中断,

Started PATCH "/components/11" for 127.0.0.1 at 2016-09-06 14:31:08 +0800
Processing by ComponentsController#update as JS
Parameters: {"utf8"=>"✓", "component"=>{"name"=>"", "alias"=>"", "pictures_attributes"=>[{"id"=>"", "name"=>"poster", "url"=>"0510000057CE600F6714C06411004555", "md5"=>"9ff2d30b17de8fc75163faff99c18afc"}, {"id"=>"", "name"=>"poster", "url"=>"0510000057CE60BF6714C063340BE1DC", "md5"=>"c5641765c087043ddc937ac5938c98d2"}, {"name"=>"poster", "url"=>"", "md5"=>""}], "release_id"=>"", "component_type_id"=>"", "x_axis"=>"", "y_axis"=>"", "width"=>"", "height"=>"", "unitary"=>"true", "ratio"=>"", "column"=>"", "hints"=>{"left"=>"", "mid"=>"", "right"=>""}, "remark"=>""}, "commit"=>"更新模块", "id"=>""}
User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
Component Load (0.2ms) SELECT `components`.* FROM `components` WHERE `components`.`id` = 11 LIMIT 1
(0.1ms) BEGIN
Picture Load (0.2ms) SELECT `pictures`.* FROM `pictures` WHERE `pictures`.`imageable_id` = 11 AND `pictures`.`imageable_type` = 'Component' AND `pictures`.`id` IN (33, 34)
Picture Exists (0.4ms) SELECT 1 AS one FROM `pictures` WHERE `pictures`.`name` = BINARY 'poster' AND (`pictures`.`id` != 34) AND `pictures`.`imageable_type` = 'Component' LIMIT 1
Component Exists (0.2ms) SELECT 1 AS one FROM `components` WHERE `components`.`name` = BINARY '' AND (`components`.`id` != 11) AND `components`.`release_id` = 1 LIMIT 1
(0.2ms) ROLLBACK
Completed 422 Unprocessable Entity in 23ms (ActiveRecord: 3.4ms) ActiveRecord::RecordInvalid (验证失败: Pictures name已经被使用):

原因是在controller的update方法里加了!,变成了update!(component_params), 去掉后的方法如下

  def update
if @component.update(component_params)
redirect_to @component, notice: 'Component was successfully updated.'
else
render :error
end
end

去掉后的log如下

Started PATCH "/components/11" for 127.0.0.1 at 2016-09-06 15:21:37 +0800
Processing by ComponentsController#update as JS
Parameters: {"utf8"=>"✓", "component"=>{"name"=>"", "alias"=>"", "pictures_attributes"=>[{"id"=>"", "name"=>"poster", "url"=>"0510000057CE600F6714C06411004555", "md5"=>"9ff2d30b17de8fc75163faff99c18afc"}, {"id"=>"", "name"=>"poster", "url"=>"0510000057CE60BF6714C063340BE1DC", "md5"=>"c5641765c087043ddc937ac5938c98d2"}, {"name"=>"poster", "url"=>"", "md5"=>""}], "release_id"=>"", "component_type_id"=>"", "x_axis"=>"", "y_axis"=>"", "width"=>"", "height"=>"", "unitary"=>"true", "ratio"=>"", "column"=>"", "hints"=>{"left"=>"", "mid"=>"", "right"=>""}, "remark"=>""}, "commit"=>"更新模块", "id"=>""}
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
Component Load (0.1ms) SELECT `components`.* FROM `components` WHERE `components`.`id` = 11 LIMIT 1
(0.1ms) BEGIN
Picture Load (0.1ms) SELECT `pictures`.* FROM `pictures` WHERE `pictures`.`imageable_id` = 11 AND `pictures`.`imageable_type` = 'Component' AND `pictures`.`id` IN (33, 34)
Picture Exists (0.2ms) SELECT 1 AS one FROM `pictures` WHERE `pictures`.`name` = BINARY 'poster' AND (`pictures`.`id` != 34) AND `pictures`.`imageable_type` = 'Component' LIMIT 1
Component Exists (0.2ms) SELECT 1 AS one FROM `components` WHERE `components`.`name` = BINARY '' AND (`components`.`id` != 11) AND `components`.`release_id` = 1 LIMIT 1
(0.1ms) ROLLBACK
Rendering components/error.js.erb
Picture Load (0.2ms) SELECT `pictures`.* FROM `pictures` WHERE `pictures`.`imageable_id` = 11 AND `pictures`.`imageable_type` = 'Component'
Rendered shared/_image.html.erb (2.6ms)
Rendered shared/_image.html.erb (1.4ms)
Rendered shared/_image.html.erb (1.5ms)
(0.2ms) SELECT `releases`.`version_name`, `releases`.`id` FROM `releases` ORDER BY `releases`.`version_name` DESC
(0.2ms) SELECT `component_types`.`name`, `component_types`.`id` FROM `component_types`
Rendered components/_form.html.erb (36.7ms)
Rendered components/error.js.erb (52.7ms)
Completed 200 OK in 111ms (Views: 87.3ms | ActiveRecord: 1.6ms)

使用update!导致的更新时候的错误信息不显示 ruby on rails的更多相关文章

  1. struts2 中的 addActionError 、addFieldError、addActionMessage方法的区别添加错误信息

    转自:https://www.cnblogs.com/wangyp/archive/2011/07/13/2104828.html 一.addActionError("错误内容") ...

  2. Mysql查询语句使用select.. for update导致的数据库死锁分析

    近期有一个业务需求,多台机器需要同时从Mysql一个表里查询数据并做后续业务逻辑,为了防止多台机器同时拿到一样的数据,每台机器需要在获取时锁住获取数据的数据段,保证多台机器不拿到相同的数据. 我们My ...

  3. 【转】PL/SQL编辑数据"这些查询结果不可更新,请包括ROWID或使用SELECT...FOR UPDATE获得可更新结果"处理

    [转]PL/SQL编辑数据"这些查询结果不可更新,请包括ROWID或使用SELECT...FOR UPDATE获得可更新结果"处理 只要有人用了: select t.* from ...

  4. Cocos 更新时反复杀进程,导致差异更新失效的Bug

    Cocos 更新时反复杀进程时,差异更新失效的问题: 问题复现步骤: 1.在project.manifest.temp 文件下载成功后,下载Assets资源的时候杀掉进程 2.重启游戏,继续更新时会使 ...

  5. Oracle编辑数据时提示:这些查询结果不可更新,请使用ROWI或者SELECT……FOR UPDATE获得可更新结果

    我们在对Oracle数据库进行操作时,有时会在查询完结果后想要对其中的某些数据进行操作,当我们点击编辑(一个锁标志)是,会提示我们上述问题中的错误:这些查询结果不可更新,请使用ROWI或者SELECT ...

  6. 新安装的windows 10无法更新报0x80240fff错误的解决方案

    如果windows 10的安装文件比较老,可能会报0x80240fff错误导致无法更新. 网络上说的方法是选择推迟更新,因为这样貌似能让windows选择另外的更新服务器. 但实际上在我遇到的情况问题 ...

  7. 虚拟机备份克隆导致SQL SERVER 出现IO错误案例

      案例环境:   服务器配置: CPU: Intel E5-2690  RAM: 12G   虚拟机 操作系统  : Windows Server 2008 R2 Standard Edtion   ...

  8. 因用了NeatUpload大文件上传控件而导致Nonfile portion > 4194304 bytes错误的解决方法

    今天遇到一个问题,就是“NeatUpload大文件上传控件而导致Nonfile portion > 4194304 bytes错误”,百度后发现了一个解决方法,跟大家分享下: NeatUploa ...

  9. vss的ss.ini丢失或损坏导致的vss无法登录错误

    vss的ss.ini丢失或损坏导致的vss无法登录错误 Written in 2007-07-03 18:17 在vss使用过程中,不知道什么原因,会导至vss目录中的ss.ini文件损坏,此文件位于 ...

随机推荐

  1. mac系统的一些操作常识

    mac系统如何显示和隐藏文件 苹果Mac OS X操作系统下,隐藏文件是否显示有很多种设置方法,最简单的要算在Mac终端输入命令.显示/隐藏Mac隐藏文件命令如下(注意其中的空格并且区分大小写): 显 ...

  2. js初学—实现checkbox全选功能

    布局如下: <p ><input type="checkbox" id="che1"/>全选</p><div id=& ...

  3. Foundation框架--字典( NSDictionary NSMutableDictionary )

    基础知识 1.字典不允许相同的key,但允许有相同的value. 2,字典是无序的,字典不能排序. 3.字典里的内容是成对存在的,不会出现单数. 4.快速创建的方式只适合不可变字典. 不可变字典 #i ...

  4. Javascript权威指南——第一章Javascript概述

    示例:javascript贷款计算器 相关技术: 1.如何在文档中查找元素: 2.如何通过表单input元素来获取用户的输入数据: 3.如何通过文档元素来设置HTML内容: 4.如何将数据存储在浏览器 ...

  5. Java @Override报错

    问题 如果在使用Eclipse开发Java项目时,在使用 @Override 出现以下错误:The method *** of type *** must override a superclass ...

  6. JavaScript 日历

    效果图: <html> <head> <script language="javascript"> /*@ 解题思路: .计算本月有多少天(先要 ...

  7. ecshop商品-》获取促销商品

    lib_goods.php->function get_promote_goods(){} /** * 获得促销商品 * * @access public * @return array */ ...

  8. python 基本数据类型分析

    在python中,一切都是对象!对象由类创建而来,对象所拥有的功能都来自于类.在本节中,我们了解一下python基本数据类型对象具有哪些功能,我们平常是怎么使用的. 对于python,一切事物都是对象 ...

  9. JavaScript数据操作--原始值和引用值的操作本质

    我的一句话总结:原始值不管是变量赋值还是函数传递都不会改变原值,引用值不管是变量赋值还是函数传递,如果新变量重新赋值,则不会影响原引用值,如新变量是直接操作,就会影响原引用值. 首先明确,值和类型是两 ...

  10. OC-block

    #import <Foundation/Foundation.h> /* block要掌握的东西 1> 如何定义block变量 int (^sumBlock)(int, int); ...