Rails - ctrl-c ignored after starting server - ruby-on-rails

I have Ruby v1.9.3 and Rails v3.2.3 on Win7. I have no problem generating a Rails directory and starting the Ruby server, but what happens is that once the server is started I have no prompt and no code I type seems to execute.
to be specific - here is the terminal code from a session:
=> Booting WEBrick
=> Rails 3.2.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-04-30 06:25:06] INFO WEBrick 1.3.1
[2012-04-30 06:25:06] INFO ruby 1.9.3 (2012-02-16) [i386-mingw32]
[2012-04-30 06:25:06] INFO WEBrick::HTTPServer#start: pid=2112 port=3000
after this point there is no prompt and no command I type seems to produce a result (including ctrl-c).
what am I doing wrong?

This worked: Im doing a rails tutorial and this was the got me back on track. Ctrl-Pause/Break stopped the server.

I assume you're running rails server to get to this point.
Everything is working as it should. Rails is a web framework and when you run it in server mode it doesn't accept commands from the terminal. Instead Rails listens for web requests on port 3000 and responds appropriately. While the server is running the terminal window is displaying the internal server logs. Visit http://localhost:3000 while the server is running and you'll see what I mean.
If you want some command line interactivity, run rails console instead. This will load up your Rails environment but instead of listening for web requests on a port it'll give you an irb prompt where you can type ruby.

Ctrl-Pause/Break works. "Pause/Break" confused me for a little bit, so if you are new like me it is the key usually next to F12 that says "pause break". :)

Related

Cant run rails app locally after adding SSL for production

I have recently added SSL for an Heroku hosted web app but now I cant run the app locally, the browser just spins forever and then in the terminal I get this error -
$ rails s
=> Booting WEBrick
=> Rails 3.2.12 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2013-07-22 11:46:26] INFO WEBrick 1.3.1
[2013-07-22 11:46:26] INFO ruby 1.9.3 (2013-02-22) [x86_64-darwin12.4.0]
[2013-07-22 11:46:26] INFO WEBrick::HTTPServer#start: pid=34732 port=3000
[2013-07-22 11:51:07] ERROR bad Request-Line `:\x00\x00\x00'.
I don't nessessarily need SSL for development so don't need to add the thin gem or nugenix but how can I get it to run locally again?
Ryan Bates had a nice little episode on the topic of adding SSL which addresses the development environment. The configuration involves pow and nginx. I will be soon trying it out for myself but not this week.
Problem solved! By adding pow as the server I can run the app normally :)
To add POW to your app run this command curl get.pow.cx | sh and then cd ~/.pow followed by ln -s /path/to/myapp.
POW is well documented on the website http://pow.cx/ and as mentioned by another user Ryan Bates has a great video on SSL which explains how to add POW to your app -http://railscasts.com/episodes/357-adding-ssl

rails server stops when i try to use "rails s"

I'm trying to learn Ruby on Rails. When I build my app and try to run the server with rails s I get the following:
**radu#radu ~/rails_projects/first_app $ rails s
=> Booting WEBrick
=> Rails 3.2.6 application starting in development on http:// 0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-07-06 15:30:09] INFO WEBrick 1.3.1
[2012-07-06 15:30:09] INFO ruby 1.8.7 (2011-06-30) [i686-linux]
[2012-07-06 15:30:14] INFO WEBrick::HTTPServer#start: pid=8179 port=3000**
Then it stops for no apparent reason and T can't do anything except close it with ctrl+c.
What can I do to fix this?
rails s runs the web server that ships with rails. All that does is sit in the background as a process and listens for incoming web requests on port 3000 on localhost. Run it again and go to http://localhost:3000.
Are you expecting more of a console where you can interact with your application? If so, what you want is rails console which allows you to interact with your app. You can write and run code - really useful for trying out things on the fly before you commit them to code in your app.
Are you really expecting a magick in rails. Open the browser and open localhost:3000, come back here and check the logs. You need to hit the server in order to get the logs and this is how it works.

using Rails to_prepare event

I'm trying to get the to_prepare event to work on a new Rails 3.2.1 project. I've placed the following:
Rails.application.config.to_prepare do
puts 'here i am before a request'
end
into an initializer under config/initializers. According to the documentation here, this block should run on every request to the app when running in development mode, and only once in production. I'm working in development mode, and this block does not run on every request, instead it runs only when I boot up the application, and never again.
The following is a sample of output from when I load the app.
rails s
=> Booting WEBrick
=> Rails 3.2.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
here i am before a request
[2012-03-02 20:29:46] INFO WEBrick 1.3.1
[2012-03-02 20:29:46] INFO ruby 1.9.2 (2011-07-09) [x86_64-darwin11.2.0]
[2012-03-02 20:29:46] INFO WEBrick::HTTPServer#start: pid=37897 port=3000
When I make subsequent requests, the string 'here i am...' is not displayed, only the regular output from the Rails log. All my searching has only mentioned documentation that seems to tell me to do things this way. Is there anything I might be missing?
to_prepare is called every time your project is reloaded, which since Rails 3.2 means every time you change a file.
refs: https://github.com/rails/rails/issues/7152#issuecomment-8397470

Rails - no command prompt after starting server?

total n00b question here but I can't seem to find the answer searching around here or the web.
I have Ruby v1.8.7 (2009-06-12 patchlevel 174) and Rails v.2.3.5 installed on my Mac (10.6.8). I have no problem generating a Rails directory and starting the Ruby server, but what happens is that once the server is started I have no prompt and no code I type seems to execute.
to be specific - here is the terminal code from a session:
bvb:new bennettvonbennett$ ruby script/server
=> Booting Mongrel
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
after this point there is no prompt and no command I type seems to produce a result.
what am I doing wrong?
This is the correct behavior. You're not doing anything wrong.
The server runs in the foreground so that you can see the log output on every page load without having to open a specific log file. It's very helpful for debugging and staying aware of what the code you write does to the application and the database.
To return to a normal command prompt, you can send an end-of-text character (usually ctrl-c) to stop the server. Most of us Rails-folk work with multiple terminal windows open - server running in one, and others for other functions, such as the rails console, started with
ruby script/console
which will let you experiment with other Rails controller functions, much like irb for standard Ruby.
With ruby script/server you launch the webserver. Run ruby script/console if you want to execute commands against your current Rails application.
You're loooking for:
script/console
If you want to play with your project in a console.

WEBrick: RequestURITooLarge: should I update or use a different server?

I currently have:
$ rails s
=> Booting WEBrick
=> Rails 3.0.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-11-30 13:18:00] INFO WEBrick 1.3.1
[2011-11-30 13:18:00] INFO ruby 1.9.2 (2011-02-18) [x86_64-darwin10.8.0]
[2011-11-30 13:18:00] INFO WEBrick::HTTPServer#start: pid=4204 port=3000
The problem I'm having is I'm using openID for auth and getting the following error:
[2011-11-30 13:18:19] ERROR WEBrick::HTTPStatus::RequestURITooLarge
In the browser:
Request-URI Too Large
WEBrick::HTTPStatus::RequestURITooLarge
WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18) at macbook-pro.local:3000
How can I fix this? Can I update WEBrick or do I really need to use a different web server?
Thanks
In Ruby 1.9.3. source, it says that MAX_URI_LENGTH = 2083. That means that the latest version of Webrick can't handle urls longer that this. And that's what the WEBrick::HTTPStatus::RequestURITooLarge exception is telling you.
The solution therefore is to use a different web server. One of the most favourite ones is Thin:
sudo gem install thin
cd to/your/rails/app
thin -h
thin -a localhost start
Like said here, you could change the MAX_URI_LENGTH using this code:
WEBrick::HTTPRequest.const_set("MAX_URI_LENGTH", 10240)
I see you've tried unicorn: have you tried running it through bundler? Add:
gem :unicorn
to your Gemfile and run:
bundle exec unicorn_rails
to start the server and browse to http://localhost:8080.

Resources