У меня есть модели Пользователь , Учитель , Учитель Образование . TeacherEducation принадлежит Teacher , Teacher принадлежит User .Я использую вложенные атрибуты, чтобы сохранить все через одну строку в моем контроллере.Но я получаю очень странные имена полей для TeacherEducation , когда мое приложение показывает ошибки проверки.Например:
Teacher teacher education teacher education university can't be empty.
У меня нет Teacher teacher education teacher education university
имени, я установил свой псевдоним в locales / en.yml
en:
activerecord:
attributes:
...
teacher_education:
teacher_education_university: "Univer"
И яне получайте такие странные имена в моделях User или Teacher .Итак, как мне показать правильное сообщение?
Мои модели:
class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :user_login,
:password,
:teacher_attributes
has_one :teacher
accepts_nested_attributes_for :teacher
end
class Teacher < ActiveRecord::Base
attr_accessible :teacher_last_name,
:teacher_first_name,
:teacher_middle_name,
:teacher_birthday,
:teacher_sex,
:teacher_category,
:teacher_education_attributes
belongs_to :user
has_one :teacher_education
accepts_nested_attributes_for :teacher_education
end
class TeacherEducation < ActiveRecord::Base
attr_accessible :teacher_education_university,
:teacher_education_year,
:teacher_education_graduation,
:teacher_education_speciality
belongs_to :teacher
validates :teacher_education_university,
:presence => { :message => "can't be empty" }
end
Мой контроллер:
class AdminsController < ApplicationController
def create_teacher
user = User.new( params[:user] )
user.user_role = "teacher"
if user.save
...
else
all_err = user.errors.full_messages
...
user_errors = all_err.to_sentence :last_word_connector => ", ",
:two_words_connector => ", "
flash[:error] = user_errors if user_errors.present?
end
end
Мой хэш:
user: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
password: ''
teacher_attributes: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
teacher_birthday: ''
teacher_category: ''
teacher_education_attributes: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
teacher_education_graduation: ''
teacher_education_speciality: ''
teacher_education_university: ''
teacher_education_year: ''
teacher_first_name: ''
teacher_last_name: ''
teacher_middle_name: ''
teacher_sex: w
user_login: ''