Possible to 'copy and paste' a whole Rails application? - ruby-on-rails

I have a fully-functioning Rails application running on my local machine called 'first-app' in my Rails applications folder 'rails-apps'. I would like to create a second application in rails-apps (called 'second-app') which is identical to first-app, just with a different name.
Can I simply copy-and-paste first-app and rename the folder to 'second-app'? I have found only two files in the whole application which contain the term 'first-app' (application.rb and routes.rb, both in config), so presumably I would have to change their contents as well. If this 'copy-and-paste' approach is viable, are there any other files I would have to alter?
If I have to do the usual > rails new second-app, I must be able to copy and paste a lot of the files and folders from first-app. Which are the ones that I have to manually alter or construct with a rails command?

yes, it should works! Just replace in the copy-project the old terms('first-app') to 'second-app' and create a new database for the new app.

You can copy and past the first app folder and use the gem 'rename' to rename the copied app.
Follow these instructions: How to rename rails 4 app?

Just copy your app to a new folder :
$ cp your-old-app your-new-app
If you want to create a new database for the new app, in your config/database.yml rename the development database.
After that, all you have to do is
rake db:create db:migrate

Related

Rails: conflict error overwrite /home/username/blog/.gitignore?

I'm desperately trying to run a server and keep getting this mistake: conflict .gitignore
The output is:
rails new blog
exist
identical README.md
identical Rakefile
identical .ruby-version
identical config.ru
conflict .gitignore
Overwrite /home/jules/blog/.gitignore? (enter "h" for help) [Ynaqdhm]
What should I do? I'm using Ubuntu 20.04. I'm an absolute beginner.
When you run command $rails new it tries to create new rails application for you. But inside that folder that you are running this command file .gitignore already exists.
So, all that you need is to decide do you want to use your .gitignore file that already exists in current folder or to overwrite it with default one.
I think you made some mistake and just to make things simplier, try to run your command rails new blog in some separate empty folder.
It seems like you run rails new blog instead of rails s/rails server.
Since it already has all the files of a rails application called "blog", it's asking if it should overwrite the existing files with the new files it is creating because you ran rails new blog.

Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first

I'm getting this error:
Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first
But I'm not in a rails directory, I'm on the desktop. There's no .bundle files anywhere to be found. Any ideas?
cd bin/
rm -rf rails
This fixed my problem. I was also getting the same error message
"Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first.
Type 'rails' for help."
I was struggling with this over the weekend, but after lots of prodding and poking got it to work.
The problem for me was that Aptana (I believe) created a second rails script in my local bin directory (~/bin) which was called instead of the system script. This local version was older than /usr/local/bin/rails. After moving aside ~/bin/rails, "rails new fred" worked as expected.
Try creating a new folder or rails app in root folder, under ~/
I was having the same problem this morning and that's because rails was already been there while i was creating my application.
To remove the error just go to bin folder of your application and remove the rails folder, and try to create new rails application in your planned folder using rails new app_name.

How to create database from schema.rb without initializing Rails?

I am trying to create all my tables from schema.rb
I used the command: "rake db:schema:load"
However, this fails because in one of my initializers, it is referencing a model/table that obviously doesn't exist (since the database is empty)
I could comment out these lines, and then run schema:load again, but is there an alternative?
Probably the fastest way is to just move the offending initializer to a temporary directory that is outside of the app, and then run your schema load. But if that doesn't work, or isn't an option for some reason, you could always work around that by creating a bare bones rails app to do the schema load:
Create a new rails app: rails new (app)-fixer
Copy your gemfile (unless there are specific exceptions) to the fixer app.
Copy your database.yml config to the fixer app.
Copy your schema.rb file to the fixer app.
Do all appropriate "bundle install" commands as needed for your app.
Then run "rake db:drop db:create db:schema:load"
That will build up a new database from scratch, based on your current schema.
You can add a check for the table existance in your initializer.
if TheModel.table_exists?
// do something with the model
end

What to ignore in a Mercurial .hgignore for a Ruby on Rails app

I created a hello world app with rails HelloWorld command. I ended up with many directories:
app
config
db
doc
lib
log
public
script
test
tmp
vendor
Should all this be under sources control? What would be a good default .hgignore file for a Ruby on Rails app folder?
.bundle
db/*.sqlite3
log/*.log
tmp/*
.DS_Store
.orig
log/*
tmp/*
your dev database under db
can be ignored to start with.
The general rule is that if you've typed it by hand it should be in source control. If there are some scaffolding files that you didn't type but that can't be easily generated by your build system and don't often change, add them too. Avoid adding files that can be generated from other added files and non-mergeable files that change often.

how to clone a project on heroku

I have a project on heroku working fine. Now I want to create same project with different url (same code) as the one I have working now. So that I can give the new url to the customer as a 'test' site. I know in heroku i can just rename the url but I want to completely separate development from test (database wise).
What is the best solution? Do I start from scratch? cd into new folder on my machine...clone project from github...make new database -test ...push to heroku...etc. etc.
Heroku toolbelt now provides a fork method to clone an existing application. It will duplicate your app with same source code, same database data and same add-ons.
Just type :
heroku fork --from sourceapp --to targetapp
https://devcenter.heroku.com/articles/fork-app
You should check out heroku_san, I designed it specifically for deploying multiple environments to Heroku easily. It also has grown to include a lot of other niceties you'll need to automate when dealing with multiple "apps" like sharing and auto migrating with restarts.
Once you have it setup it's as simple as:
rake production deploy
I'm using a method very similar to the one presented here:
http://jqr.github.com/2009/04/25/deploying-multiple-environments-on-heroku.html
What is the best solution? Do I start from scratch? cd into new folder on my machine...clone project from github...make new database -test ...push to heroku...etc. etc.
Yeah, I'd just make a copy (clone) of the repo, either from GitHub (if you have it up on GitHub) or the current Heroku location. Then start a new project in Heroku and push the cloned (and possibly modified) second site up to Heroku as that project.

Resources