Add title length note and error info when creating project or creating news
I have encountered several times that there was none error info if the news title is too long, and the page would displayed a rails exception.
ActiveRecord::StatementInvalid in NewsController#new Mysql::Error: Data too long for column 'title' at row 1: INSERT INTO `news` (`created_on`, `project_id`, `title`, `description`, `summary`, `author_id`, `comments_count`) VALUES('2008-06-20 10:24:15', 3, 'the very long title that will cause exception', 'the news', 22, 0) RAILS_ROOT: redmine Application Trace | Framework Trace | Full Trace ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:150:in `log' ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/mysql_adapter.rb:281:in `execute'
And this will confuse the users who are not a developer.
So, I think it will be greate to add a length limit note on the creating page, and give out an error info rather than directly display the rails exception page.
#1 Updated by Chaoqun Zou over 9 years ago
I have found that this is a gloc error, but still don't know how to resolve it.
When the news' title is in Chinese, gloc's validates_length_of method will use string.split(//).size to get the title length. Every Chinese character will be treated as 1 character. But when save to mysql, every Chinese character will be treated as 3 characters. So the gloc's validates_length_of will return success but actually the string length is much longer than the maxim length.
#3 Updated by Chaoqun Zou over 9 years ago
- Status changed from New to Resolved
I have finally found the reason that this is caused by my error database.yml.
Very sorry to post these invalid messages.
This error is caused by a error configured database.yml.
This is my error config:
development: adapter: mysql database: redmine_development host: localhost username: root password: mysql
And if use chinese in the system, we must add this encoding parameter:
That is to say, when I correct my database.yml to:
development: adapter: mysql database: redmine_development host: localhost username: root password: mysql encoding: utf8
the problem is resolved!