Vote #63483
完了Add title length note and error info when creating project or creating news
0%
説明
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.
For example:
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.
journals
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.
--------------------------------------------------------------------------------
Sorry about last post, that when I removed gloc's validates_length_of method and let active_record do the validates, I found that the activerecord's validates_length_of is the same as gloc's...
--------------------------------------------------------------------------------
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:
<pre>
development:
adapter: mysql
database: redmine_development
host: localhost
username: root
password: mysql
</pre>
And if use chinese in the system, we must add this encoding parameter:
<pre>
encoding: utf8
</pre>
That is to say, when I correct my database.yml to:
<pre>
development:
adapter: mysql
database: redmine_development
host: localhost
username: root
password: mysql
encoding: utf8
</pre>
the problem is resolved!
--------------------------------------------------------------------------------
Thanks for the feedback. I've added this setting in @database.yml.example@.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------