I have recently changed my app to read a model's constants in from YAML files stored in Amazon S3 (set up in application.rb in an after_initialize). This works without a problem, except WEBrick seems to be losing the constants. It works fine when started, but after some time I'll refresh a view and it will report that the constant isn't initialized. There are no errors, and restarting the WEBrick server resolves the problem.
I'd be grateful for any advice.
Rails 4.1.6 application starting in development ..
INFO WEBrick 1.3.1
INFO ruby 2.1.2 (2014-05-08) [x86_64-linux]
Related
No Rails command will exit on the first CTRL-C. So rails s or rails c require me to hit control CTRL-C a second time and commands that previously wouldn't have required a CTRL-C at all such as rake routes / db:migrate now require me to press it.
The issue is not happening for any of my teammates. I'm on OSX using iTerm2. There are no instances of 'rescue Exception' in the app.
I've just reinstalled mysql using brew and the issue is still present. Rails version 4.0.5 and sql server version 5.6.27. Any idea where the issue might be?
[2016-01-13 16:18:33] INFO WEBrick 1.3.1
[2016-01-13 16:18:33] INFO ruby 2.1.2 (2014-05-08) [x86_64-darwin13.0]
[2016-01-13 16:18:33] INFO WEBrick::HTTPServer#start: pid=2329 port=3000
^C[2016-01-13 16:18:54] INFO going to shutdown ...
[2016-01-13 16:18:54] INFO WEBrick::HTTPServer#start done.
Exiting
^C
Honestly Webrick 1.3.1 was released in December 28, 2011 I would suggest moving away from this see webrick answer for the reasons.
As you have said that it happens in rails consoles and other tasks (You should really put this in the question as it helps with debugging) I would suggest it is a gem that is causing this (You should update your rails version anyway) but I would suggest using:
Ctrl-D
This should exit you straight away
I suspect this isn't as much an answer as a suggestion, but I started using Puma by default in my projects a while back, and given that Rails 5 is moving to Puma by default it may not be a bad suggestion.
I use a similar environment, OS X 10.11.2, iTerm 2, tmux, etc. I can't recall when or what prompted it, but at some point my WEBrick projects started behaving this same way, and I started moving them to Puma where possible which didn't seem to show the same behavior.
I know that doesn't really give a clear answer as to what's causing the issue, but also, I too know it's not system performance related.
WEBrick usually writes its output to both development.log and stdout. However it suddenly stopped doing so and it is not writing to stdout. All we're getting is
Booting WEBrick
=> Rails 3.2.8 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
and then nothing. development.log seems to be written to properly.
This is a project-specific problem because it's happening to all members of our team in different computers. On the other hand if I create another Rails project (and copy the Gemfile and Gemfile.lock to ensure I have the same gems) I get the normal output on the terminal.
This is a big problem because among other things it prevents us from using pry or ruby-debug since I have no access to the process on a breakpoint.
We're using Ruby ruby-1.9.3-p194, Rails 3.2.8 and WEBrick 1.3.1. In case it matters we're all on Macs (Mountain Lion).
Any ideas what could be causing this and how to solve it? We need stdout back! Thanks
It turned out that someone had added these three lines to config.ru
log = File.new("console.log", "a+")
$stdout.reopen(log)
$stderr.reopen(log)
It was very painful to figure out this one, so needless to say, don't do that.
If you use pry-remote you should be fine.
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". :)
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
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
I am a Newbie on Ruby on Rails, and I've had some issues with the deployment of RoR applications.
EDIT 1: Trying to narrow down the question a bit. I am uncertain whether my issues with the deployment of my rudimentary Ruby apps are results of my erroneous setup and coding or conflicts in the version of Ruby on Rails I am currently using.
Rephrasing question: What version of Ruby on Rails should I use? Being a newbie to the frameworks, I just want my deployment process to be as smooth as possible. If 3.2 is the official download (as of jan 20, 2012) is it safe to use, and should I then use the latest stable version of Ruby (1.9.3-p0)? What about gems mentioned in books and writings? Should I always use the latest one?
Old discussion
I am following Ruby On Rails Tutorial. Following the instructions in the book I try to deploy on Heroku, but with no luck. Printouts from the Heroku log gives:
2012-01-22T18:26:09+00:00 app[web.1]: Started GET "/pages/about" for 90.231.141.39 at
2012-01-22T18:26:09+00:00 app[web.1]: cache: [GET /pages/about] miss
2012-01-22T18:26:09+00:00 app[web.1]: ActiveRecord::ConnectionNotEstablished
(ActiveRecord::ConnectionNotEstablished):
This application does not use any database at this point (only presenting static pages). So to me the ActiveRecord error comes as no suprise. Uncertain though if this is the root to the problem. I first thought that this issue was realted to Heroku, since my rails server deployment worked fine, but the I found the rails server -e production command to run the rails server in production environment. Under Rails 3.1.3 this renders the page correctly, but I still get the following error message in the server log:
sample_app$ rails server -e production
=> Booting WEBrick
=> Rails 3.1.3 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-01-22 23:07:28] INFO WEBrick 1.3.1
[2012-01-22 23:07:28] INFO ruby 1.9.3 (2011-10-30) [x86_64-darwin11.2.0]
[2012-01-22 23:07:28] INFO WEBrick::HTTPServer#start: pid=57161 port=3000
cache: [GET /] miss
cache: [GET /pages/about] miss
Started GET "/pages/about" for 127.0.0.1 at 2012-01-22 23:09:50 +0100
Processing by PagesController#about as HTML
Rendered pages/about.html.erb within layouts/application (2.0ms)
Completed 200 OK in 24ms (Views: 24.2ms | ActiveRecord: 0.0ms)
cache: [GET /assets/application-cd728f3a08415c27ca2e753d30091c74.css] miss
It seems to me that there is some kind of routing issue. But my lack of knowledge and experience with RoR makes me a lame duck in the search for the actual error.
Upgrading to Rails 3.2.0 made the issue even worse. I made a sample app for Rails 3.2 basically with:
rails new test_app
Entered the "test_app" folder and ran rails server -e production (using Ruby 1.9.3-p0). This time the default Ruby on Rails index page was not even rendered. The server log gives me:
heroku_test$ rails server -e production
=> Booting WEBrick
=> Rails 3.2.0 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-01-22 23:19:07] INFO WEBrick 1.3.1
[2012-01-22 23:19:07] INFO ruby 1.9.3 (2011-10-30) [x86_64-darwin11.2.0]
[2012-01-22 23:19:07] INFO WEBrick::HTTPServer#start: pid=63242 port=3000
cache: [GET /] miss
So, it seems in all cases like I have some issues with my routing or my caching or wathever.
These are my specs:
System specs: Mac OS X Lion 10.7.2
Ruby: 1.9.3-p0
Rails: 3.1.3 (and also 3.2.0 release the other day)
I am very aware that these specs are not what Ruby on Rails Tutorial propose. The RoR tutorial is written with the follow Specs in mind:
Ruby: 1.9.2 (or 1.8.7)
Rails: 3.0.11
In chapter 13, Hartl explains the difference with Rails 3.1.x and sports an upgrade guide for the sample_app. I've skimmed through this chapter (since I am stuck at chapter 3) but have been unable to find a remedy to my problems.
What is my question really?
How do I deploy a RoR app to production for a version of RoR that runs on my system?
Related links and sources I've browsed so far, apart from the regular pages on RoR.org and Heroku.com:
cache: [GET /] miss? dalli gem, memcached, rails 3.1, nginx, unicorn production environment
How does one load a CSS framework in Rails 3.1?
rails 3 tutorial: No route matches [GET] “/”
Rails 3.1 on Heroku Cedar
Now that the question has changed:
"What version of Ruby on Rails should I use? Being a newbie to the frameworks, I just want my deployment process to be as smooth as possible."
If you are learning from a book or tutorial, use the same version as the examples in that book/tutorial.
"What about gems mentioned in books and writings? Should I always use the latest one?"
Most gems have dependencies on other gems, so the exact version you use will often depend on those dependencies. Sometimes you may even discover a bug in one version, so you switch to another version to remedy the problem. Or again, if you are following a book/tutorial which uses a certain version, you may want to use the same version (at least while you are working through the tutorial). If, though, you have no good reason to use an old version, then generally you should use the newest one.
Have you learned how to use Bundler? It allows you to control the exact versions of each gem which you want to use.
#jollyCocoa, the error you got when deploying to Heroku was caused by not having the database set up. Even if you're not using the database, if you configure the database connection anyways, it will fix this error. If you are starting with RoR, though, and just want something to experiment with, don't try deploying to Heroku at this point. Just start with a very simple application running locally, even just the "skeleton" application generated by "rails new", and make changes one small step at a time, checking at each step that the app is still working. If you get stuck and can't figure out how to get a certain feature working, you can post a more specific question.