Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running multiple instances of Rails Server

I am new to Rails, so please forgive me if this is obvious.

I am doing a lot of experimenting, creating to applications, testing features, etc. It got my first scaffolded app running great, but I wanted to create a second app to test a different feature.

I backed up a folder level on my computer, ran $ rails new taskmaster (a test to-do list app). I ran the scaffolding for the Task model, fired up the server via $ rails server, and attempted to load http://localhost:3000.

But I got a routing error, saying it couldn't find the "members" route. But members was from my first Rails app! I thought by firing off $ rails server in the taskmaster directory, it would startup the server for that application.

How do I tell the Rails server which application to serve up?

UPDATE

I just discovered that if I:

  1. Roll back to the fresh install of the first Rails app, before I created the Member scaffold
  2. Fire up the rails server via $ rails server in the application's root directory
  3. Check http://localhost:3000

It still attempts to go for the members route, the one that no longer exists because I rolled back via git.

I'm guessing this means something in my /usr/local/ area, relating to my Ruby and Rails initial installs, is mainatining this info (my apps are setup in my Documents folder in my home dir).

I thought that Rails apps were essentially self contained apps inside the directory - you just needed a working Ruby install to get them going. Does the Rails server sit inside each app directory, or is the some overarching Rails server that accommodates all apps?

like image 716
Dave W. Avatar asked Feb 08 '11 01:02

Dave W.


2 Answers

You can run multiple instances of webrick server on localhost by assigning a different port number as:

rails s -p 3007 

But sometimes it may not work.

I have a tip for you.You can try using this along with other options provided by webrick. Just try with providing any number as PID using -P :

rails s -p 3007 -P 42342 
like image 33
Jaswinder Avatar answered Sep 24 '22 11:09

Jaswinder


I suspect the old server was still running and the new server failed to start. Try killing it first and then start it your new app.

Alternatively, you could start the new server on a different port by using the -p switch (e.g. rails server -p 3001)

like image 138
cam Avatar answered Sep 24 '22 11:09

cam