2013-01-09 10 views
5

Seit Schienen 3.2.9 kann ich Modelle in Unterordnern nicht speichern. In meiner app habe ich diesen Baum:Schienen 3.2.9 und Modelle in Unterordnern

models 
-type_models 
-assets 
-user 
-concerns 

Auch in application.rb ist es

config.autoload_paths += Dir["#{config.root}/app/models/*"] 

Alles war in Ordnung, bis Schienen 3.2.9. Jetzt habe ich den Fehler "Unbekannte Konstante". Ich möchte nicht Tonnen von Modell namespace und alle App reparieren, um namespaced Modelle zu verwenden.

Warning: Error loading /var/www/my_app/app/models/type_models/context_type.rb: 
uninitialized constant TypeModels::ContextType 

Datei context_type.rb:

class ContextType ... end 
+3

Warum möchten Sie nicht alle Modelle mit einem Namensraum versehen? Das ist die Konvention. – Baruch

+0

Weil es in 3.2.8 ok war? –

+0

Haben Sie eine Lösung gefunden? – Lichtamberg

Antwort

0

Versuchen zu verwenden:

config.autoload_paths += Dir["#{config.root}/app/models/**/"] 
+1

Warnung: Fehler beim Laden von /var/www/my_app/app/models/type_models/context_type.rb: nicht initialisierte Konstante TypeModels :: ContextType –

+0

Siehe: http: //stackoverflow.com/questions/18934115/rails-4-organize-rails-models-in-sub-path-without-namespacing-models Haben Sie Ihre App nach der Änderung neu gestartet? – RubeOnRails

-1

Ihre class ContextType ... end Wickeln Modul:

module TypeModels 
    class ContextType 
    # blah blah 
    end 
end 
0

in config/application.rb:

config.autoload_paths += %W(type_models assets user concerns).map { |folder| "#{config.root}/app/models/#{folder}"} 

in models/type_models/context_type.rb:

class TypeModels::ContextType < ActiveRecord::Base 
    ... 
end 

Restart Rails und du bist fertig!