使用update!导致的更新时候的错误信息不显示 ruby on rails
在图片管理里添加了校验方法之后,发现在更新的时候页面不显示校验报错的信息
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的更多相关文章
- struts2 中的 addActionError 、addFieldError、addActionMessage方法的区别添加错误信息
转自:https://www.cnblogs.com/wangyp/archive/2011/07/13/2104828.html 一.addActionError("错误内容") ...
- Mysql查询语句使用select.. for update导致的数据库死锁分析
近期有一个业务需求,多台机器需要同时从Mysql一个表里查询数据并做后续业务逻辑,为了防止多台机器同时拿到一样的数据,每台机器需要在获取时锁住获取数据的数据段,保证多台机器不拿到相同的数据. 我们My ...
- 【转】PL/SQL编辑数据"这些查询结果不可更新,请包括ROWID或使用SELECT...FOR UPDATE获得可更新结果"处理
[转]PL/SQL编辑数据"这些查询结果不可更新,请包括ROWID或使用SELECT...FOR UPDATE获得可更新结果"处理 只要有人用了: select t.* from ...
- Cocos 更新时反复杀进程,导致差异更新失效的Bug
Cocos 更新时反复杀进程时,差异更新失效的问题: 问题复现步骤: 1.在project.manifest.temp 文件下载成功后,下载Assets资源的时候杀掉进程 2.重启游戏,继续更新时会使 ...
- Oracle编辑数据时提示:这些查询结果不可更新,请使用ROWI或者SELECT……FOR UPDATE获得可更新结果
我们在对Oracle数据库进行操作时,有时会在查询完结果后想要对其中的某些数据进行操作,当我们点击编辑(一个锁标志)是,会提示我们上述问题中的错误:这些查询结果不可更新,请使用ROWI或者SELECT ...
- 新安装的windows 10无法更新报0x80240fff错误的解决方案
如果windows 10的安装文件比较老,可能会报0x80240fff错误导致无法更新. 网络上说的方法是选择推迟更新,因为这样貌似能让windows选择另外的更新服务器. 但实际上在我遇到的情况问题 ...
- 虚拟机备份克隆导致SQL SERVER 出现IO错误案例
案例环境: 服务器配置: CPU: Intel E5-2690 RAM: 12G 虚拟机 操作系统 : Windows Server 2008 R2 Standard Edtion ...
- 因用了NeatUpload大文件上传控件而导致Nonfile portion > 4194304 bytes错误的解决方法
今天遇到一个问题,就是“NeatUpload大文件上传控件而导致Nonfile portion > 4194304 bytes错误”,百度后发现了一个解决方法,跟大家分享下: NeatUploa ...
- vss的ss.ini丢失或损坏导致的vss无法登录错误
vss的ss.ini丢失或损坏导致的vss无法登录错误 Written in 2007-07-03 18:17 在vss使用过程中,不知道什么原因,会导至vss目录中的ss.ini文件损坏,此文件位于 ...
随机推荐
- 二维码(QRcode)容量的计算与版本
4.版本信息:即二维码的规格,QR码符号共有40种规格的矩阵(一般为黑白色),从21x21(版本1),到177x177(版本40),每一版本符号比前一版本每边增加4个模块. 177 = 21+(40- ...
- Python2.7安装(win7)
Python可在官方网站直接下,或者百度一下Python2.7下载,这里推荐使用2.7而不是3.3,比较适合初学者 工具/原料 win7系统 python2.7安装包 方法/步骤 1.从官网下载最新的 ...
- 自然语言22_Wordnet with NLTK
QQ:231469242 欢迎喜欢nltk朋友交流 https://www.pythonprogramming.net/wordnet-nltk-tutorial/?completed=/nltk-c ...
- 分享jquery实现百叶窗特效的图片轮播
首先非常感谢网友嘉翼的无私分享,这是他刚在网站扣下来的特效,第一时间与大家分享,jquery实现百叶窗特效的图片轮播 使用方法: 1.引用css文件,css文件里面已经做了注释,基本只需要修改宽高就好 ...
- php 多条数据更新
mysql更新语句很简单,更新一条数据的某个字段,一般这样写: 1 UPDATE mytable SET myfield = 'value' WHERE other_field = 'other_va ...
- UITableViewCell的separator分隔线设置失效
// 处理separator -(void)viewDidLayoutSubviews { if ([self.tableView respondsToSelector:@selector(setSe ...
- 正则匹配IP
分析 IP地址的长度为32位,分为4段,每段8位,用十进制数字表示,每段数字范围为0~255( 2^8 ),段与段之间用英文句点“.”隔开.例如:某台计算机IP地址为10.11.44.100. IP地 ...
- 平衡二叉树(AVL)c语言实现
参考: 二叉平衡树的插入和删除操作 平衡二叉树,AVL树之图解篇 [查找结构3]平衡二叉查找树 [AVL] #include "stdio.h" #include "st ...
- Spring Ioc--Bean装配
继前一篇IoC概述.Spring容器总结,接下来总结下Bean的装配过程. 要使引用程序中的Spring容器成功启动,需要同时具备以下3个条件: 1.Spring框架的类包,放在应用程序的类路径下. ...
- Win7电脑无法启用无线连接或无线连不上网
1. 上不去网,看是否是无线网卡禁止. 2. 打开控制面板--网络和Internet--查看网络状态和任务--更改网络适配器 3. 4.若启用后无线网络连接仍为灰色,继续往下看 5.点击开始,找到运行 ...