Tag: Rails 2.3.8

Handling large seed files in Ruby on Rails

Sometimes seed files can get messy and big. It can be real pain it the ass to manage them. Here is fast way to split single seeds.rb file:

  1. Create directory called seeds in your db/ directory (mkdir ./db/seeds)
  2. Remove all stuff from seeds.rb and move it into your newly created files under db/seeds/ directory (put them accordingly to your own app logic)
  3. Paste code presented below into seeds.rb file
  4. Run rake db:seed

Seeds.rb file source code:

# coding: utf-8

%w{
  filename1 filename2 filename3...filenameN
}.each do |part|
  require File.expand_path(File.dirname(__FILE__))+"/seeds/#{part}.rb"
end

Why haven't I use auto-include and instead I've listed all the files? Well I wanted to maintain my seed parts load order so those parts will be loaded accordingly to my order (not based on file names).

Rails 3.1 [DEPRECATION WARNING] Nested I18n namespace lookup is no longer supported

New Rails, new i18n, new warnings:

[DEPRECATION WARNING] Nested I18n namespace lookup under "activerecord.attributes.admin" is no longer supported
[DEPRECATION WARNING] Nested I18n namespace lookup under "activerecord.attributes.scanlation" is no longer supported
[DEPRECATION WARNING] Nested I18n namespace lookup under "activerecord.attributes.manga" is no longer supported
[DEPRECATION WARNING] Nested I18n namespace lookup under "activerecord.attributes.character" is no longer supported

From now on, you cannot use nested namespaced models translations. Lil bit weird since I remember, that when I've been moving from 2.3.7 to 3.0 I needed to do opposite thing.

Fix is easy to implement, just replace nested stuff like:

pl:
  admin:
    su: "Super user"

with slash separeted names:

pl:
  "admin/su": "Super user"

Same for attributes and warning will disappear.

Copyright © 2024 Closer to Code

Theme by Anders NorenUp ↑