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

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. oneM2M标准发展神速 实现万物联网的愿景

    http://m2m.iot-online.com/news/2013102224849.html oneM2M则将负责解决独立于接取网路中通用的M2M服务层的关键需求:使其可更方便地嵌入于各种软硬体 ...

  2. 使用WebService和不使用WebService哪个速度更快哪个更安全

  3. Extjs GridPanel用法详解

    Extjs GridPanel 提供了非常强大数据表格功能,在GridPanel可以展示数据列表,可以对数据列表进行选择.编辑等.在之前的Extjs MVC开发模式详解中,我们已经使用到了GridPa ...

  4. MFC学习-第一课 MFC运行机制

    最近由于兴趣爱好,学习了孙鑫的MFC教程的第一课.看完视频了,自己便用visual studio 2010尝试了MFC编程,其中遇到了一些问题. 1.vs2010不像vs6.0那样可以新建一个空的MF ...

  5. emacs最简单入门,只要10分钟

    macs最简单入门,只要10分钟  windwiny @2013    无聊的时候又看到鼓吹emacs的文章,以前也有几次想尝试,结果都是玩不到10分钟就退出删除了. 这次硬着头皮,打开几篇文章都看完 ...

  6. Jquery实现textarea根据文本内容自适应高度

    本文给大家分享的是Jquery实现textarea根据文本内容自适应高度,这些在平时的项目中挺实用的,所以抽空封装了一个文本框根据输入内容自适应高度的插件,这里推荐给小伙伴们. autoTextare ...

  7. input 框 宽度100%时 padding 超出问题解决

    如下图: 让input  宽度100%, 加边框并有左填充,这里如果用 padding-left: 的话,input 边框会超出100%的范围 后来发现 text-indet: XXpx; 即可实现即 ...

  8. html、css杂记

    1:浮动 <div style="float: left"> 2:清除浮动,把父div撑起来 <div style="clear:both"& ...

  9. java web项目实现文件下载

    现在项目里面有个需求,需要把系统产生的日志文件给下载到本地先获取所有的日志文件列表,显示到界面,选择一个日志文件,把文件名传到后台: File file = new File(path);// pat ...

  10. 两个select转移

    <table> <tr> <td> <select multiple="multiple" id="leftSelect&quo ...