3

I'm new to programing and rails and I'd like to create a copy of a rails app I'm working with to harmlessly try out some things. Is there an easy way to make that happen?

BenU
  • 2,287
  • 1
  • 22
  • 35

1 Answers1

9

Yes you can. These commands weren't obvious to a newbie like me and may help someone else...

First, depending on what you plan on calling your new deployed app, find a name that is currently available on heroku.

From root of old and to be created new rails app:

$ cp -R old_directory new_directory
$ cd new_directory
$ rm -rf .git
# find and replace all references to old_director found within new_directory
# the command at the terminal 'grep -ri "old_director" .' may help to locate 
# all of the references to the old_directory
$ git init
$ git add .
$ git ci -am “First commit after copying from old_app”
# create new_directory repository at github.  Follow along their 
# directions for new repository with appropriate modifications.  
$ git remote add origin git@github.com:[github username]/[new_directory].git
$ git push -u origin master
$ rake db:migrate
$ heroku create [new_app]
$ git push heroku master

To generate a new secret key for your new app:

$ rake secret  # generate new secret key for new app
5ed8c7d9a3bda9cec3887b61f22aa95bf430a3a550407642b96751c7ef0ce8946a161506d6739da0dcaaea8c8f4f8b3335b1fb549e3cc54f0a4cec554ede05f8

Next, save the newly created secret key as an environmental variable on Heroku with the following command:

$ heroku config:set SECRET_KEY_BASE=5ed8c7d9a3bda9cec3887b61f22aa95bf430a3a550407642b96751c7ef0ce8946a161506d6739da0dcaaea8c8f4f8b3335b1fb549e3cc54f0a4cec554ede05f8

More details about storing secret keys, etc., as environmental variables can be found on Daniel Fone's Blog.

Finally:

$ heroku run rake db:migrate
BenU
  • 2,287
  • 1
  • 22
  • 35
  • Running `$rake db:migrate` followed by `$rake db:test:prepare` or `rake db:test:load` and then running specs may be a good idea prior to pushing to git and deploying to Heroku. – BenU Mar 17 '13 at 18:46
  • Do you need to make any changes to the secret key? – Onichan Nov 30 '15 at 07:04
  • 1
    Yes @Onichan. You should generate a new secret key using `$ rake secret` and save it as a heroku environmental variable. I'll edit my instructions above to include those steps. – BenU Dec 01 '15 at 23:37