Rails engine migrations, schema dump, and dependencies. -


i following tutorial on creating rails engines , i'm curious whether or not need list of host's dependencies (i'm creating rails engine called admin inside larger rails application) inside engine's gem file (apparently engine accessed via gem). why need this?

also why engine need of host's migrations? or engine need migrations relevant files i'm moving on engine?

an engine should independent host. it's isolated in code , data, , should able drop any host , work same way. means engine doesn't have special knowledge of inner workings of host, , host has no special knowledge of engine's internals.

if engine depends on model called admin, should include migration template creating admins table , 100% of code needed interact admins. migration template copied host's db/migrations folder , run alongside other migrations. don't add migrations engine itself, because it'll have no way of running them once it's inside host. remember: engine cannot know internal host, including database schema.

i recommend create , maintain separation. it'll save huge headaches in future.

within engine, need include dependencies , code engine alone. not add dependencies or code required host, because engine isn't allowed know them.

this harder sounds, there great examples of engines can follow. check out railsadmin , devise high-quality samples of code organization, data management, , testing.

testing important. in order engine display pages or interact, may need include dependencies rails. can that, make sure add them development dependencies gemfile. see above projects examples of how this.

i recommend build engine outside host project, because it'll force write tests don't rely on host app. if engine testable , works on own, it'll work great when drop host too.


Comments