2010-12-07 9 views
1

私はレールで初心者だけど、今日は検証を使用して私の最初のWebアプリケーションを作った、私はちょうどモデルにこのラインを置く:RoRの=>奇妙な検証メッセージ

class ClientWorkout < ActiveRecord::Base 

    validates_numericality_of :paid_amount 
    validates_presence_of :client_name 

end 

これは、ビューの一部です:

<% form_for(@client_workout) do |f| %> 
    <%= f.error_messages %> 
     etc etc 

すべてが正常に動作し、その値を<ビューでこのエラー表示は、この奇妙な、以下のようにして、代わりに、エラーoccour場合に成功した場合に、DBに格納されている:

{{count}} errors prohibited this {{model}} from being saved 

There were problems with the following fields: 
{{attribute}} {{message}} 
{{attribute}} {{message}} 

(この例は、フォームの2つのパラメータが間違っている場合を示していますが、すべての場合に発生します)
「カウント、モデル、属性およびメッセージ」を実際の値に置き換えることはできません。 何が起こったのか誰でも知ることができますか? 私はRor 2.3.8とレールを使用しています。1.8.7

答えて

1

Railsは2.3に組み込まれた国際化を導入しました。あなたの問題は、レールとi18nの宝石の組み合わせによっては既知のバグです。 i18n gemバージョン0.5.0を使用している場合は、0.4.2にダウングレードしてみてください。あなたは、システムの宝石使用している場合:

sudo gem uninstall i18n 
sudo gem install i18n -v 0.4.2 

を、あなたの宝石を管理するためにRVMを使用している場合は、sudoコマンドは必要ありません。

+0

私は宝石i18 0.4.2をインストールすることはできません。ユニバージョン0.5.0をnstallしました。検証メッセージは正しい方法で動作するようになりましたが、バージョン0.4.2では偽のインストールが行われ、偽のインストールでは次のような意味があるため、宝石はありません:peppe @ ubuntu:〜$ sudo gem install i18n -v 0.4.2 i18n-0.4.2をインストールしました 1つのgemがインストールされています i18n-0.4.2のドキュメントをインストールしています... i18n-0.4.2のRDocドキュメントをインストールしています。 peppe @ ubuntu:〜$ gem list | grep i18n peppe @ ubuntu:〜$ – Joe

0

あなたは次の操作を行うことができます国際化バージョンを変更するに興味を持っていない場合 en:はすでに利用可能なコピーである場合config/locales/en.ym

に以下のコードを追加し、それがサーバーを停止した後のActiveRecord

から貼り付け、もう一度やり直してください...

en: 
    activerecord: 
    errors: 
     full_messages: 
     format: "%{attribute} %{message}" 
     messages: 
     inclusion: "is not included in the list" 
     exclusion: "is reserved" 
     invalid: "is invalid" 
     confirmation: "doesn't match %{attribute}" 
     accepted: "must be accepted" 
     empty: "can't be empty" 
     blank: "can't be blank" 
     too_long: "is too long (maximum is %{count} characters)" 
     too_short: "is too short (minimum is %{count} characters)" 
     wrong_length: "is the wrong length (should be %{count} characters)" 
     not_a_number: "is not a number" 
     not_an_integer: "must be an integer" 
     greater_than: "must be greater than %{count}" 
     greater_than_or_equal_to: "must be greater than or equal to %{count}" 
     equal_to: "must be equal to %{count}" 
     less_than: "must be less than %{count}" 
     less_than_or_equal_to: "must be less than or equal to %{count}" 
     other_than: "must be other than %{count}" 
     odd: "must be odd" 
     even: "must be even" 
     template: 
     header: 
      one: "1 error prohibited this %{model} from being saved" 
      other: "%{count} errors prohibited this %{model} from being saved 
+0

素晴らしいです。私はこの同じ問題をトラブルシューティングしようとしていました。それはi18nの問題であると考えていました。私は他のプロジェクトに出掛けたときに戻ってきたことを思い出しました。しかし、あなたのテンプレートにマッチしたメッセージをどう扱うか分からなかった:header:あなたが投稿した.ymlファイルのother。スーパーヘルプ。ありがとう。この問題を修正したとしても、意図しない副作用を伴うかもしれないgemのバージョンを変更するよりもはるかに優れた解決策です。 –