【发布时间】:2012-08-19 19:59:37
【问题描述】:
所以我已经设置了 best_in_place gem [https://github.com/bernat/best_in_place],但是当我尝试编辑的列看起来像 title_name 并且发生错误时,我遇到了一个小问题 p>
'title_name can't be blank,is too short (minimum is 1 characters)'
我想编辑 gem 处理错误显示的方式,以便它将 _ 替换为 space 并可能稍微改一下 user-friendly
编辑:
检查响应我通过 Firebug 得到的是:
{"title_name":["can't be blank","is too short (minimum is 1 characters)"]}
在 gem 演示中的位置 http://bipapp.heroku.com/users/59
["Last name has invalid length","Last name can't be blank"]
这有点不同...
EDIT2:
post.rb
class Post < ActiveRecord::Base
attr_accessible :post_id, :title_name, :total_items, :user_id
validates :title_name, :presence => true, :length => { :in => 1..50 }
belongs_to :user, :foreign_key => 'post_id'
self.primary_key = :post_id
def to_param
"#{post_id}"
end
end
【问题讨论】:
-
@rudolph9 我找不到任何可以使用的选项来更改通过 gem api 显示错误的方式,这就是为什么我在这里发布它,猜测有人可能以前遇到过同样的问题......
-
这是一个有趣的问题。查看example app,如果您为
last_name输入一个 字符,则会返回错误“姓氏长度无效”,其中表中的条目为last_name。跨度> -
继续克隆示例并将
last_name折射为last_curseword,应用程序现在会生成输出“Last curseword has invalid length”。 -
我也在 github 上搜索代码,但在使用 gem 的方式上我找不到任何与我的应用程序不同的东西......仍在搜索
-
我已经用我在 ajax 响应中发现的差异编辑了这个问题......这可能是问题,但我不确定......
标签: ruby-on-rails error-handling best-in-place