Two rails apps sharing a model folder

前端 未结 7 493
半阙折子戏
半阙折子戏 2020-12-23 22:14

I have two rails apps running off the same database, one which runs the client and one which provides an admin interface.

Both the apps have the exact same models de

7条回答
  •  一整个雨季
    2020-12-23 22:45

    Yes, symlink the models directory, but then add an environment variable to your environment.rb for each instance. Then your models can know which instance is using it and include additional validations or what not.

    in environment.rb:

    APP_INSTANCE = "app1"
    

    in model.rb

    validates_length_of :name, :within => 3..100, :if => :is_app_one?
    
    def is_app_one?
        APP_INSTANCE == "app1"
    end
    

提交回复
热议问题