Scott's Recipes Logo

A Shell Script to Move Files from 1 Rails App to Another

Last Updated On: 2025-09-01 04:31:52 -0400

Rails apps are often like swiss watches – intricate, complex and if one thing goes wrong – they fall apart and only creating a new Rails app can help you. This script copies the guts of a Rails app to a newly generated rails app.

Note: If you have this problem and think you need this, try deleting Gemfile.lock before you use this. My good friend Nick Janetakis made this suggestion after I wrote this and a post mortem showed it worked.

echo "A shell script to copy the files from one rails app to another" 
echo ""
echo "Syntax and Usage:"
echo ""
echo "change into the rails app where you want to copy things into"
echo ""
echo "i.e. cd ~/Sync/coding/rails/imgarr"
echo ""
echo "Run this with a path to the rails app you want to copy stuff from:"
echo ""
echo "cp_from_rails_to_rails ../turbo-rails-tutorial-code"
echo ""
echo ""

read -p "Press any key to continue..."

mkdir db/migrate
cp -p -r $1/app/views/* app/views
cp -p -r $1/app/models/* app/models
cp -p -r $1/app/helpers/* app/helpers
cp -p -r $1/app/controllers/* app/controllers
cp -p -r $1/app/assets/stylesheets/* app/assets/stylesheets
cp -p -r $1/db/migrate/* db/migrate
cp -p -r $1/config/routes.rb config
cp -p $1/config/initializers/simple_form.rb config/initializers
cp -p -r $1/test/* test

echo "Now manually move over Gemfile entries and any other config/initializer stuff "