Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby

Diego Ante
Diego Ante
5,251 Points

Generate a Rails Application

I'm having trouble generating the application from the command prompt. I'm working on Windows 7 but I can't figure out how to follow along with the tutorial.

15 Answers

Once you create a new rails app (# rails new <app_name>), you go into the directory and start generating the controller/view/models you need. You can also do scaffolding go get everything in one shot.

Generate a controller: # rails generate controller Users

Generate a model: # rails generate model user

Generate a scaffold: # rails generate scaffold Users

Diego Ante
Diego Ante
5,251 Points

Thank you very much, I think I got it, but the problem is that I have to relaunch the command prompt I do any action, because it seems to freeze, but if I restart it it works ok now and I can follow to the next step.

If you launch the rails server with the "-d" option it should detach from the command line and allow you to work / follow along without interference.

rails s -d

Diego Ante
Diego Ante
5,251 Points

The problem is that I'm not being able to stop the server from the command prompt on windows with ctrl + c

You'd have to look up that process in the task manager most likely and kill it. Unless you are making changes to the DB or authentication you shouldn't have to start/stop the server. The new controllers and models should be accessible immediately without stopping the server.

You could also leverage something like Virtualbox if you wanted to.

Diego Ante
Diego Ante
5,251 Points

I'm not understanding anything sorry, I had never worked with the command prompt before :S

No problem :-P

If you are using Windows (assuming you are currently) you can use the -d option when starting the rails server so that the server starts to run in the background. This will allow you to continue working. You don't need to relaunch the rails server each time you generate a new controller.

When you are done working for the day you will need to open the task manager in windows to find the process that is running the rails server, and terminate it.

Does this make more sense?

Diego Ante
Diego Ante
5,251 Points

Much more thank you, but this is the exact command I'm running: "rails server -d" but when I go to http://localhost:3000/ through my browser it says that it doesn't find the page

Try http://127.0.0.1:3000

Also make sure there is no firewall blocking you (although not usually likely for localhost or 127.0.0.1 connections)

Jim Hoskins
STAFF
Jim Hoskins
Treehouse Guest Teacher

When you are running the server, you can't run other commands, because that window is busy, being a server.

On most operating systems, the way to stop the current task (like the server) is to hold ctrl and hit c (ctrl+c). I believe on windows this sometimes doesn't work, and instead you need to hold ctrl and hit the break key (ctrl+break). This should stop the server so you can run any command, then you start the server again.

running with -d can be tricky because you don't have the handle to kill your server when you need to. If you don't want to restart your server each time you need to run a command, you could use two command prompt windows. However, some things will require restarting the server anyway to update your app (like installing gems).

Hope that helps!

Diego Ante
Diego Ante
5,251 Points

Thank you! the solution with ctrl+break is working great for now!

Deleted User

have also same problem

Jim Hoskins
STAFF
Jim Hoskins
Treehouse Guest Teacher

Hi Jeylan,

Are what operating system are you using? Is hitting ctrl+break stopping the server, and returning you to the command line?

Deleted User

Hi Jim I use wndows xp the command starts with c.// Sites not under Ruby/projects/ treebook as I watched on the video.