0

I am working on a Sharetribe website. I added the following line to my person.rb file:

validates_presence_of :address_line_1, on: :update

But when the error notification message appears, it says translation missing: en.layouts.notifications.[:address_line_1, "can't be blank"]

I've searched online and I can't see how I should add this translation?

FYI, Sharetribe runs on Ruby 2.1.2 and Rails 3.2.21.

4

1 回答 1

1

所有语言环境都在“config/locales/en.yml”文件中定义。在文件中添加错误的翻译,如下所示:

layouts:
  notifications:
    address_blank_error: "Address line 1 can't be blank"   

并且,在您的 people_controller.rb 中将代码更新为:

def update
  . 
  .
 if target_user.update_attributes(.....)
   .....
 else
   if target_user.errors[:address_line_1].present?
     flash[:error] = t("layouts.notifications.address_blank_error")
   else
     flash[:error] = t("layouts.notifications.#{target_user.errors.first}")
   end
 end
于 2018-01-16T13:27:58.210 回答