我有一个应用程序,可以从输入到模型中的正文文本创建文本摘录,它似乎能正常工作,除了某些原因,当我尝试输入一个特定的字符串正文文本。Rails截断后的“列数据太长”错误
在我blog_post模型我
t.string "excerpt", limit: 114
在我的控制器
我正在做这个创造摘录字符串:
def create
@blogpost = Blogpost.new(blogpost_params)
@excerpt = @blogpost.body
@blogpost.excerpt = truncate(@excerpt, :length => 114)
respond_to do |format|
if @blogpost.save
etc,etc,
end
这似乎精细工作的大部分时间,但我进入下面的文本作为测试
You know how they used to say It's #Sinatra's world, the rest of us are just living in it. - well, it's as true today as it was then. Check out Frank. When he gets out of a #chopper, dressed in a perfect lounge suit, #cocktail in hand, his #hat stays perfectly tilted. When I get out of a #chopper (and I'm not talking about once or twice but every single time I ever get out of a chopper) the spinning blades blow my hat all over the place. #Milliners should think about that and you should too the next time you're out hat shopping.
(对不起,它有点长)我得到以下错误:
ActiveRecord::StatementInvalid in MoansController#create
Mysql2::Error: Data too long for column 'excerpt' at row 1....
它看起来像截断工作不因某种原因..难道是与这段文字,或我错过了什么东西?
这个列是如何在MySQL中定义的?那里的最大长度是多少? –
您使用的是哪个版本的Rails? –
它的轨道4和用于添加列的迁移是add_column(:blogposts,“摘录”,:字符串,:极限=> 114) –