実現したいこと
該当のソースコード
application.rb
1# Require the gems listed in Gemfile, including any gems 2# you've limited to :test, :development, or :production. 3Bundler.require(*Rails.groups) 4 5module InstructorMatching 6 class Application < Rails::Application 7 # Initialize configuration defaults for originally generated Rails version. 8 config.load_defaults 7.0 9 10 config.i18n.default_locale = :ja 11 12 # Configuration for the application, engines, and railties goes here. 13 # 14 # These settings can be overridden in specific environments using the files 15 # in config/environments, which are processed later. 16 # 17 # config.time_zone = "Central Time (US & Canada)" 18 # config.eager_load_paths << Rails.root.join("extras") 19 20 # Don't generate system test files. 21 config.generators.system_tests = nil 22 end 23end
config/locales/ja.yml
1ja: 2 activerecord: 3 attributes: 4 user: 5 name: "表示名" 6 password: "パスワード" 7 password_confirmation: "パスワード確認" 8 email: "メールアドレス"
erb
1<% if instructor.errors.any? %> 2 <div style="color: red"> 3 <h2><%= pluralize(instructor.errors.count, "error") %> prohibited this instructor from being saved:</h2> 4 5 <ul> 6 <% instructor.errors.each do |error| %> 7 <li><%= error.full_message %></li> 8 <% end %> 9 </ul> 10 </div> 11 <% end %> 12
試したこと
https://zenn.dev/machamp/articles/rails-validation-message
こちらの記事を参考にgemのインストールも完了しております。
gem install 'rails-i18n'
こちらのコマンドのみ実行済です。
補足
もしかしたらgemが正しくインストールされていない可能性があります...
Gemfile
1source "https://rubygems.org" 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby "3.2.2" 5 6# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" 7gem "rails", "~> 7.0.5" 8 9# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] 10gem "sprockets-rails" 11 12# Use mysql as the database for Active Record 13gem "mysql2", "~> 0.5" 14 15# Use the Puma web server [https://github.com/puma/puma] 16gem "puma", "~> 5.0" 17 18# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] 19gem "importmap-rails" 20 21# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] 22gem "turbo-rails" 23 24# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] 25gem "stimulus-rails" 26 27# Build JSON APIs with ease [https://github.com/rails/jbuilder] 28gem "jbuilder" 29 30# Use Redis adapter to run Action Cable in production 31# gem "redis", "~> 4.0" 32 33# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] 34# gem "kredis" 35 36# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] 37# gem "bcrypt", "~> 3.1.7" 38 39# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 40gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] 41 42# Reduces boot times through caching; required in config/boot.rb 43gem "bootsnap", require: false 44 45# Use Sass to process CSS 46# gem "sassc-rails" 47 48# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] 49# gem "image_processing", "~> 1.2" 50 51gem "ridgepole" 52 53gem "seed-fu" 54 55gem "sorcery" 56 57gem "administrate" 58 59group :development, :test do 60 # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem 61 gem "debug", platforms: %i[ mri mingw x64_mingw ] 62end 63 64group :development do 65 # Use console on exceptions pages [https://github.com/rails/web-console] 66 gem "web-console" 67 68 # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] 69 # gem "rack-mini-profiler" 70 71 # Speed up commands on slow machines / big apps [https://github.com/rails/spring] 72 # gem "spring" 73end
gemのインストールのやり方も教えていただけますと幸いです。
よろしくお願い致します。
追加記載
- Gemfileにgemの追加をし、bundle installを実行しました。
2. ja.ymlファイルの作成
3. application.rbに1行追加
ターミナルでのエラー内容
viewのSyntaxerrorの発生
解決
ja.ymlファイルをこのようにすることで解決できました
ya.yml
1ja: 2 activerecord: 3 attributes: 4 instructor: 5 name: "名前" 6 email: "メールアドレス" 7 password: "パスワード" 8 password_confirmation: "パスワード(確認用)" 9 errors: 10 models: 11 instructor: 12 attributes: 13 name: 14 blank: "を入力してください" 15 email: 16 taken: "は既に存在します" 17 password: 18 too_short: "は %{count} 文字以上で入力してください" 19 password_confirmation: 20 blank: "を入力してください" 21 messages: 22 confirmation: "と%{attribute}が一致しません" 23 24モデルと合わせることが重要でした!! 25
回答2件
あなたの回答
tips
プレビュー