プロジェクト

全般

プロフィール

Vote #63483

完了

Add title length note and error info when creating project or creating news

Admin Redmine さんが約2年前に追加. 約2年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
-
対象バージョン:
開始日:
2008/06/20
期日:
進捗率:

0%

予定工数:
category_id:
0
version_id:
5
issue_org_id:
1506
author_id:
460
assigned_to_id:
0
comments:
5
status_id:
5
tracker_id:
2
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

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@.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

Admin Redmine さんが約2年前に更新

  • 対象バージョン0.7.3_5 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0