how to re-initialize a ruby on rails project - ruby-on-rails

I've just been given a folder containing everything in a ruby on rails project that was developed 2 years ago. The folder doesn't contain a sqlite3 file however, so I am unable to view the database and I currently don't know how to run the application on my local computer.
What are the steps to re-starting a previously developed project so that further development can be done to it?
Thanks!

Owwwwww that is hard.
I see two main problems: gem dependencies and the database.
Gem dependencies are now cleanly managed with bundler, but two years ago that was not the case.
Getting all the gems you need for your project together will be the hardest part (depending on the size of the project).
Gem dependencies
Previously gems had to be defined in config/environment.rb, but actually require could be scattered all over the app, and depending on the discipline of the original developers, I guess no versions were specified. So it will be hard to compose a set of working gems, since a lot of gems change between versions.
In config/environment.rb you will also find the rails version.
Use rvm and a clean gemset. If the rails version is something 2.3.x, you could start using bundler.
Database
If you find a config/database.yml: then you know which type of database was expected. Adapt it to connect to your database (of the same type). If there is no such thing, start off with sqlite3, as it will cope with most simple cases (it will get you started).
The simplest way to get the database up and running is
rake db:create
rake db:setup
This will create an empty database (from your configuration), and then load the schema and the seeds.
Next steps
get the tests running (hopefully there are any)
consider upgrading to rails 3
Hope this helps.

First you'll need a config/database.yml file that defines how Rails connects to your database. If that's already in there, hopefully it's not in your versioning system :)
Second, you'll need to create the databases. You can do that with rake db:create.
Third, you will need to load the database schema. DO NOT do rake db:migrate as Dave mentioned in the comment above. This is not the recommend way to load the schema since it's slower and may not accurately represent the schema. Instead, use rake db:schema:load.

Related

What should I know before changing my development database?

Since I learned Rails from Micheal Hartl's tutorial, all of my apps are set up to use SQLite3 in development, but Postgresql in production. This is causing problems with searches that work in development but not in production. From other Stack overflow questions, I've learned that using different databases in different environments is a bad idea.
I think that my best solution is to change the development database to Postgresql. But I'm sure that it's not as simple as adjusting the db name in my gemfile. What other changes will I need to make? What are some potential side effects that I should be aware of?
Thank you in advance for any insight.
You can do it two ways.
First Way :
Below are steps you can follow to convert sqlite to postgres.
Install postgres.
Change your Gemfile in your rails app and add PG gem.
Run bundle install.
Change the database.yml file to use postgres.
Run rake db:setup followed by rake db:migrate.
Everything should work as expected, Because with rake db:setup and rake db:migrate you will get identical database as before.
Second Way :
Now rails also provide way to directly change DB from one DB to another, You can check here.
Just use below command and you are done.
bin/rails db:system:change --to=postgresql
Copy Data as well :
If you want to copy data as well you can use yaml_db gem.

How do I download and run a rails app?

As an example, I want to download: https://github.com/banker/newsmonger and tinker with it (to learn Rails). I've downloaded the zip and when I go into that folder and type rails server, the terminal window says to create a new rails app
This is a Rails 2 application, and so as ennuikiller said, you'll need to run script/server.
You may run into problems with dependencies not being installed in this application, which is a problem that normally (now) would be solved with Bundler. Due to this being a Rails 2 application, it doesn't support Bundler out of the box and the owner of the repo hasn't updated it to support that, and so you're dead outta luck there.
What you'll need to do is attempt to run rake gems:install (which may or may not work, depending on the sun's positioning) which will install the gems specified in config/environment.rb and the proper config/environments files using the config.gem methodology. This was how it was done in Rails 2, and caused so many problems that Bundler was created.
If that doesn't work, contact that banker guy on GitHub and ask him what the deps are or work out the dependencies yourself.
Good luck!
Depending on the version of rails this app uses you may have to execute the following :
script/server

Rake vs. Warbler in Ruby?

I have used Warble to make .war files. That worked pretty well.
Some of the tutorials online suggest using the "rake" command at various times. If rake is for compilation, I thought Ruby didn't need compilation. Is it a substitute for Warble? Or do these two play different functions?
When is rake meant to be used?
Rake is a tool written in Ruby for automating tasks, which you also write using a Ruby syntax. Ruby program's don't have to be built, but there are still plenty of other tasks involved in development that you can automate instead of doing yourself each time.
Some examples from Rails include migrating your database to a new schema or creating a new database.
Rake lets you write tasks with a Ruby syntax, and you can also specify dependencies between tasks, so that running one task will cause all of its dependencies to be ran first.
Think of rake as a make for Ruby. For example for one of the gems I develop, the Rakefile includes several tasks, like running all the tests (rake test) or building the gem (rake gem:build). More info on the web site:
http://rake.rubyforge.org/

Why won't my tutorial rails app work?

I'm learning rails with "agile web development with rails (3rd edition)" and I've gotten to the point where I'm supposed to make the depot app.
I have created the depot app, and I've added the script/generate files. I've raked the db. For some reason, no tables where created in the migration and upon running this command:
depot> sqlite3 db/development.sqlite3 "select version from schema_migrations"
I get nothing. Then when running localhost in my browser, instead of getting what I'm supposed to, I get the standard welcome to rails page.
Any advice?
Resolved:
It's always the simple things. Had to direct to localhost:3000/products instead of just to localhost:3000 - wasn't aware of this. Thanks!
There is a number of possibilities here, firstly, judging by the fact you can see the standard "Welcome to Rails" page you haven't deleted public/index.html - you should do this so that Rails can route to the root /
Secondly, if your migrations are running correctly you should have a schema.rb file in ./db with the instructions for each table, if not then something is failing there.
I have not read the 'Agile web development with Rails" book but I am assuming it was written before the release of Rails 3, which means your app does not use Bundler for gem dependency management so it might be worth checking that sqlite3 gem is installed. You can check this with gem list sqlite if you don't see something like "sqlite3-ruby (1.3.2)" then you need to install it.
Lastly, check the log files in ./log/
Well I guess you've created multiple migrations by now so try typing rake db:migrate at the command line and let use know what it says?

How do I install all the gems from my environment.rb (Rails 2)

I tried rake gems:install but I get
No such file or directory - /Users/macuser/Sites/hq_channel/config/database.yml
I bet the default is set wrong.
What file do I need to change? And where do I find what to change it to?
it can't find your database.yml file, which is a required config file that should have been generated when you made a new project. Without that being there, the rails environment won't start, which means no rake tasks work
Often times folks create a database.yml.example. I typically do a:
[rails_root]$cp config/database.yml.example config/database.yml
Edit the file to match my environment, then try to install the gems/migrate the DB.
However - this is often times hit-or-miss due to a plethora of different reasons (environment.rb code, bootstrapping/initializer issues, vendored gems w/ C extensions, etc..).
If the app is on Rails 2.3 (you only specified 2), you may be able to override the standard rake gems:install with a little Bundler joy.

Resources