You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Rails应用遇LoadError:无法加载I18n文件求助

Hey, I’ve run into similar issues when precompiling assets for Rails 5.x apps—let’s walk through fixing both the deprecation warning and the LoadError step by step.

Fixing the Erubis Deprecation Warning

This warning pops up because Rails 5.1 started phasing out Erubis in favor of Erubi, a faster, better-maintained alternative. To resolve it:

  1. Open your config/application.rb file.
  2. Inside the class Application < Rails::Application block, add this line (you can place it right after config.load_defaults 5.1 if that’s present):
    config.action_view.template_handlers[:erb] = ActionView::Template::Handlers::ERB::Erubi
    
  3. Save the file—this tells Rails to use Erubi instead of Erubis, and the warning should disappear on your next precompile run.

Resolving the I18n LoadError

This error typically comes from missing dependencies, invalid locale files, or misconfigured I18n settings. Try these troubleshooting steps in order:

  • Verify the i18n gem is installed correctly
    Run bundle show i18n in your terminal. If it returns an error saying the gem isn’t found, re-run bundle install to ensure all production dependencies are installed. For production environments, use bundle install --deployment to lock dependencies to the versions in your Gemfile.lock.

  • Check for YAML syntax errors in locale files
    Invalid YAML in your config/locales/ directory is a common culprit. Even a missing space after a colon or mismatched quotes can break locale loading. Validate your YAML files with this command (replace en.yml with each locale file in the directory):

    ruby -e "require 'yaml'; YAML.load_file('config/locales/en.yml')"
    

    If a file has syntax issues, this command will throw an error pointing to the problem line.

  • Double-check I18n configuration
    Open config/application.rb and config/environments/production.rb to confirm your settings are correct:

    • Ensure config.i18n.load_path isn’t pointing to non-existent files.
    • Verify config.i18n.default_locale is set to a valid locale (like :en).
    • Remove any custom I18n initializers you recently added if they might be overriding default behavior.
  • Ensure compatibility between activesupport and i18n
    Rails 5.1.6 requires a specific range of i18n versions (usually ~> 0.7 or ~> 0.9). Check your Gemfile.lock to see which version you’re using. If it’s incompatible, add a version constraint to your Gemfile:

    gem 'i18n', '~> 0.9.5'
    

    Then run bundle update i18n to install a compatible version.

  • Confirm your Ruby and bundle environment match
    Sometimes the error happens if you’re using a different Ruby version than the one your bundle was installed with. Run ruby -v and bundle exec ruby -v—they should show the same version. If not, switch to the correct Ruby version (using rbenv, rvm, or chruby) and re-run bundle install.

Once you’ve addressed both issues, try running the precompile command again:

bundle exec rake assets:precompile RAILS_ENV=production

内容的提问来源于stack exchange,提问作者Ray Wojciechowski

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:00:46