我有一個應用程序,可以從輸入到模型中的正文文本創建文本摘錄,它似乎能正常工作,除了某些原因,當我嘗試輸入一個特定的字符串正文文本。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) –