0

私はSharetribe Webサイトに取り組んでいます。person.rbファイルに次の行を追加しました。

validates_presence_of :address_line_1, on: :update

しかし、エラー通知メッセージが表示されると、translation missing: en.layouts.notifications.[:address_line_1, "can't be blank"]

オンラインで検索しましたが、この翻訳を追加する方法がわかりません。

参考までに、Sharetribe は Ruby 2.1.2 と 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 に答える