How do I download and run a rails app? - ruby-on-rails

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

Related

Giving a 'test drive' to the app before following the book 'learn-ruby-on-rails'

I've been following Daniel Kehoe's book Learn Ruby on Rails and it is amazing.
I wanted to give the finished official app a test drive before continuing to better understand where I'm heading to, however I'm not sure how to do this (given the fact that I'm just beginning the book).
I forked the "learn-rails" repo from the RailsApps GitHub account and cloned it into my Mac with the name "learn-rails-guide" (as "learn-rails" was already taken for following along). When tried to start the server, I got an error saying that I should run 'bundle install'.
I did so, hoping that the gemset created during the following along won't get messed up; however 'bundle' wasn't able to install the 'pg' gem. And I hit a road block...
Is this problem related to changing the name of the app?
Does this have something to do with the finished app being set up for production?
Am I taking the wrong approach for trying the finished app locally?
Will an app with a .ruby-gemset and a .ruby-version files mess up my current gemsets if a run bundle install?
Thanks!
Use $ bundle install --without production (see the book's deploy chapter). Otherwise, you'll need to install PostgreSQL locally (which can be difficult). The repo version of the app is the final version that includes gems for deploying to Heroku.
There will be no problem with changing the name of the folder that contains the app.

Ruby on Rails - ran "gem update," printed lots of text, but no gems actually updated?

I ran gem update the other day in Command Prompt with Ruby and Rails. There was a flurry of text, and it said such things as ...rdocs rails 4.0.0 (I forget exactly what it was saying) and all in all it took about 40 minutes (the rails 4.0.0 listings seemed to be longest.) However, I used bundle install after that, and I'm still using 3.3.2 rails, and worse, using old models of all the other gems (most noticeably shoulda and shoulda-matchers.) Please help me see what I did wrong, whatever it might have been. I'd like to update my gems all at once, if appropriate (I am new so I don't know if its recommended.)
If you want to update your project gems (which features updating Gemfile.lock and actually updating proper gems), you need to run:
bundle update
To run an RoR command line on a project, you have to make sure you are in that project's root folder beforehand. For example, if your projects are in c:\projects and you are working on project trythisone, you need to be in c:\projects\trythisone before you run bundle update or any similar command.
You probably don't need rdoc, anyway, so follow this advice. To be clear, in Windows 8 you would need to go to your users folder and add a file called ".gemrc". Thus, for a user called "myuser", you would have a file at: (Earlier Windows versions would be in their particular users folder)
c:\users\myuser\.gemrc
This file would contain the following text:
gem: --no-ri --no-rdoc
Marek Lipka was correct in that bundle update is needed.

Missing Gemfiles in Rails Install

Bit of a strange question, but here goes.
I'm a relative beginner to rails, and I've just started working on my second app locally. However, after each install I'm getting the following problem - that several gemfiles are missing (railties being the most obvious).
So, I deleted the install, re-ran it and listed the gemfiles - they are all there. However, after initializing a git repo and pushing the project up to my GitHub a gem list command shows that a number of gems are now missing - at this point I can't run any rake commands or for example rails server.
So I cleared the repo and re-installed. gem list says the gems are all present, server and rake commands work; but push the repo and it subsequently packs up - gem list shows only a handful of gems remain.
Bearing in mind my experience, I'm prepared to believe I'm missing something very obvious, but any advice would be appreciated.
welcome ;-)
I suppose you want to create a Rails 3 application. So first make sure you have installed bundler.
gem install bundler
The steps for creating the application are:
rails new your_app
Then run bundler in the applications folder:
cd your_app
bundler install
Now you should be able to run the application:
rails s
Go and visit localhost:3000. If that does not work, you have other problems. Paste the stack trace then ...
The problem was I forgot that I had two versions of Ruby installed and I had not properly set a default with rvm for some reason. Specifying the default then checking the gems were present for that version of Ruby fixed it.

"could not locate gemfile" when doing bundle install on existing rails project

I've been given an existing rails project that I am trying to play around with. however, when I try to run bundle install or rake db:migrate, I run into problems so essentially, i can't really do anything with the code I've been given.
The biggest problem as I see it right now is the fact that it can't locate my gemfile when I bundle install?
How can I find my gemfile.. is there supposed to be one in the root folder of the application?
Is there another step I need to take to initialize an existing project that someone has just copied and pasted to me? Thanks!
Yes, you should have a Gemfile in the root directory of your app.
If you are developing in a Rails 2 app, you might want to check out the Bundler.io page about Rails 2.3:
http://bundler.io/v1.7/rails23.html
If you are using Rails 3+ you can take a learn from Bundler's page on Rails 3 use:
http://bundler.io/v1.7/rails3.html
If you just need to get started with a Gemfile, go to a different directory and generate a dummy app:
$ rails new temporary-app
Copy over the Gemfile to your directory. It will only have the default gems listed, but you may be able to "discover" your needed gems as you go. If you happen to have a Gemfile.lock file then you can see the gems that you need at the top of the dependency tree.

Do I need to revert to an older version of Rails just to run a single legacy app (among other problems)?

I have an older Rails app that I need to run. But I have the latest version of Rails.
When I try to run this older app it says:
Missing the Rails 1.99.0 gem. Please
gem install -v=1.99.0 rails
But when I run the command: gem install -v=1.99.0 rails
ERROR: could not find gem rails
locally or in a repository
Not sure what to do next. Could someone help me understand what's happening here?
And my second question, related to this problem is: It seems silly that I need to revert to an older version of Rails just to run this one legacy app - there must be a better way of doing this?
AFAIK, v1.99.0 is sort of a v2.0 prerelease, so you could try installing v2.0.x, changing the RAILS_GEM_VERSION in config/environment.rb and runing rake rails:update.
If you think about it, it's not as silly as it might seem at first. You make an app using a fast evolving web framework as RoR. Your choices are: continue developing your app at aproximately the same pace the framework is evolving, or freeze the rails gem (and evertything else your app depends on, like gems, plugins) into your app in order to make it less fragile to expecting gem updates.
Regarding the second question: yes it is silly. Fortunately the Rails team spotted that silliness and at some point they gave us the ability to "freeze" the versions of Rails libraries required by an application (and also specific gem versions) into the vendor directory.
To freeze your version of Rails:
rake rails:freeze:gems
There's a good blog post from a while back describing this.
Unless you install and deploy RVM, your installation will roll back your system rails installation, which will impact your other projects. If you want to manually administrate your development environment this way, you can uninstall rails first, and then install the desired version of rails for the current project.
But try to install your rails gem instead with this syntax:
sudo gem install rails -v 1.99.0

Resources