开发者

Formtastic: Validation error messages not translating locale template vars to value

Rails v2.3.8

formtastic v1.1.0

Forms draw correctly, validation works, but the validation messages for anything involving the length of a string are showing up as:

is too short (minimum is {{count}} characters)

Basically {{count}} is not getti开发者_开发技巧ng filled in. In irb, I can see that the value is in the @options of the ActiveRecord::Errors:

>> u.errors
=> #<ActiveRecord::Errors:0x7f98785b4ab0 @errors=#<OrderedHash {"password"=>[#<ActiveRecord::Error:0x7f9878561b30 @type=:too_short, @options={:default=>nil, :count=>4},...

Note that this is a validation on a User model being performed by authlogic v2.1.6 (which may not be relevant).

--- UPDATE --------- :

After some more digging, I copied the en.yml locale file out of the activerecord-2.3.8 gem dir and into my local app config/locales dir. After changing all the {{count}} to %{count} things are now displaying properly.

Maybe a bug with formtastic v1.1.1 working with rails v2.3.8? The changelog speaks to a few things generally that it could possibly fall under. There are several newer versions of formtastic available. I unfortunately cannot upgrade this environment so I am going to setup another to test the newer formtastic versions.


Messages that display things like {{count}} and also {{model}} and {{attributes}} have been seen a lot recently and can also be due to servers having Rails3 apps on them.

There are a couple of common fixes:

1) Bump up from 2.3.8 to 2.3.9 or 2.3.10 Very minor change, should not affect anything else (though test of course). So just change your rails version in environment.rb

2) include the gem for a version specific il8n, e.g. (0.4.2), in environment.rb, add a line for:

gem il8n, :version => '0.4.2'

bundler can help a lot too, Though standard with Rails3, I believe the steps to change an existing 2.3.x app to use it (isn't that what you usually need to know?) are as follows. Well, obviously install it, prob. gem install bundler then take (eventually deleting them there) all your existing 'gem...' statements from your environment.rb file and put them in a Gemfile then with commands like: bundle install or bundle update you can create a 'bundle'. The above command create a Gemfile.lock that has the versions you're using.

Also if you have multiple cucumber versions or issues tests running in IDE's the next commands may be needed: bundle exec cucumber features/user_can_login.feature or bundle exec cucumber features/user_can_login.feature:6 (specific line number).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜