Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
897 views
in Technique[技术] by (71.8m points)

ruby - Why doesn't Rails' "errors.full_messages" replace attribute and message variables?

Having a strange problem with a rails model I just created.

Here are my validations:

validates_presence_of :from_name, :message => 'Please provide a from name.'
validates_presence_of :from_email
validates_presence_of :giftition_plan_id

I'm having issues using errors.full_messages as well as f.error_messages in my form:

g = Giftition.create
g.errors.first
=> ["from_name", "Please provide a from name."]
>> g.errors.full_messages
=> ["{{attribute}} {{message}}", "{{attribute}} {{message}}", "{{attribute}} {{message}}"]

I'm just getting "{{attribute}} {{message}}". Any ideas?

UPDATE: I've uninstalled rails 3 and all the gems that were installed with it and that made the problem go away. It's not a fix though... I would still like to have rails 3 installed.

UPDATE: Sounds like upgrading to 2.3.9 fixes the problem. Unfortunately, I've given up for now, but sometime in the future I will try that.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I ran into this problem as well with an old 2.3.5 Rails app that I inherited. I had the 5.0 version of the i18n gem installed. I saw that it needs the %{} syntax. Doing this in config/locales/en.yml did the trick:


en:
  activerecord:
    errors:
      full_messages:
        format: "%{attribute} %{message}"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...