I'm a newbie in rails, today I made my first web application using the validate, I just put this lines into the model:
class ClientWorkout < ActiveRecord::Base
validates_numericality_of :paid_amount
validates_presence_of :client_name
end
This is the view part:
<% form_for(@client_workout) do |f| %>
<%= f.error_messages %>
etc etc
Everything works fine, and the value are stored in the db, in succesful case< if an error occour, instead, this error displays on the view in this strange following manner:
{{count}} errors prohibited this {{model}} from being saved
There were problems with the following fields:
{{attribute}} {{message}}
{{attribut开发者_如何学Ce}} {{message}}
(The example show what's happening when 2 parameters of the form are wrong, but this happen in every case)
It doesen't manage to replace "count, model, attribute and message" with the real value. Anyone can figure out about what's happenned ? I use Ror 2.3.8 and rails 1.8.7Rails introduced built-in internationalization back in 2.3. Your issue is a known bug with some combinations of rails and the i18n gem. If you have i18n gem version 0.5.0, try downgrading to 0.4.2. If you're using system gems:
sudo gem uninstall i18n
sudo gem install i18n -v 0.4.2
If you're using RVM to manage your gems, you don't need the sudo
command.
If you are not interested in changing the i18n version you can do the following
Add the below code in config/locales/en.ym
If en:
is already available copy and paste from ActiveRecord
After that stop the server and start again that should display the error messages properly...
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
精彩评论