rails s hangs - Hartl Rails Guide - ruby-on-rails

I'm a beginner and just installed everything on my system (new) per the Hartl guide. I am having issues with 'rails s' - it hangs and doesn't continue so I'm unable to do anything except end the command line processes and start over. Here's where it stops:
$ rails s
=> Booting WEBrick
=> Rails 4.0.2 application starting in development on (localhost3000)
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-01-03 00:13:30] INFO WEBrick 1.3.1
[2014-01-03 00:13:30] INFO ruby 2.0.0 (2013-11-22) [x86_64-darwin13.0.0]
[2014-01-03 00:13:30] INFO WEBrick::HTTPServer#start: pid=22805 port=3000
Started GET "/microposts/new" for 127.0.0.1 at 2014-01-03 00:13:38 -0800
ActiveRecord::SchemaMigration Load (0.6ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by MicropostsController#new as HTML
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
Rendered microposts/_form.html.erb (71.3ms)
Rendered microposts/new.html.erb within layouts/application (90.6ms)
Completed 200 OK in 237ms (Views: 222.5ms | ActiveRecord: 0.4ms)
Started GET "/assets/users.css?body=1" for 127.0.0.1 at 2014-01-03 00:13:39 -0800
Started GET "/assets/microposts.css?body=1" for 127.0.0.1 at 2014-01-03 00:13:39 -0800
Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2014-01-03 00:13:39 -0800
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2014-01-03 00:13:39 -0800
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2014-01-03 00:13:39 -0800
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-01-03 00:13:39 -0800
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-01-03 00:13:39 -0800
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-01-03 00:13:39 -0800
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-01-03 00:13:39 -0800
Started GET "/assets/microposts.js?body=1" for 127.0.0.1 at 2014-01-03 00:13:40 -0800
Started GET "/microposts/new" for 127.0.0.1 at 2014-01-03 00:19:11 -0800
Processing by MicropostsController#new as HTML
Rendered microposts/_form.html.erb (6.1ms)
Rendered microposts/new.html.erb within layouts/application (8.0ms)
Completed 200 OK in 19ms (Views: 17.9ms | ActiveRecord: 0.0ms)
Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2014-01-03 00:19:12 -0800
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2014-01-03 00:19:12 -0800
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-01-03 00:19:12 -0800
Started GET "/assets/microposts.js?body=1" for 127.0.0.1 at 2014-01-03 00:19:12 -0800
Started GET "/assets/users.css?body=1" for 127.0.0.1 at 2014-01-03 00:19:12 -0800
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-01-03 00:19:12 -0800
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-01-03 00:19:12 -0800
Started GET "/assets/microposts.css?body=1" for 127.0.0.1 at 2014-01-03 00:19:12 -0800
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2014-01-03 00:19:12 -0800
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-01-03 00:19:12 -0800

As stated, rails server takes over the terminal when you run it. You've got to start a new terminal session. A quit step in ubuntu/linux is the combination
CTL+SHIFT+T
or
CTL+ALT+T

When you run "rails s" it takes over the terminal and doesn't return. You should open a second terminal if you want to run other commands at the same time.
In production you usually setup rails with apache or nginx. See this guide for more information:
http://rubyonrails.org/deploy

I had this same question at first. It look like it's hanging but that actually means that it's running. As long as it looks like it's hanging it is running the server and you can open the localhost:3000 to see your webpage locally. When you're ready to shutdown the server and get your prompt back you can click control c on the mac.

Related

Action cable direct connection (Expected HTTP 101 response but was '404 Not Found' + Failed to upgrade to WebSocket)

I'm trying to open a direct websocket connection to the route of my action cable. Unfortunately that's not working. I'm only getting this error when curling or just hitting http://localhost:3000/cable directly..
Started GET "/cable" for 127.0.0.1 at 2019-02-06 20:04:08 -0600
Started GET "/cable/"[non-WebSocket] for 127.0.0.1 at 2019-02-06 20:04:08 -0600
Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: keep-alive, HTTP_UPGRADE: )
Finished "/cable/"[non-WebSocket] for 127.0.0.1 at 2019-02-06 20:04:08 -0600
This is the exception in my client:
java.net.ProtocolException: Expected HTTP 101 response but was ‘404 Not Found’
But if I hit http://localhost:3000/page/index with a browser, I see the following output:
Started GET "/page/index" for 127.0.0.1 at 2019-02-06 20:05:30 -0600
Processing by PageController#index as HTML
Rendering page/index.html.erb within layouts/application
Rendered page/index.html.erb within layouts/application (0.3ms)
Completed 200 OK in 28ms (Views: 25.5ms | ActiveRecord: 0.0ms)
Started GET "/cable" for 127.0.0.1 at 2019-02-06 20:05:30 -0600
Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2019-02-06 20:05:30 -0600
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
User Load (0.7ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT $1 [["LIMIT", 1]]
↳ app/channels/application_cable/connection.rb:12
Registered connection (Z2lkOi8vd2hvcy1yZWFkeS1hcGkvVXNlci8z)
RoomChannel is transmitting the subscription confirmation
RoomChannel is streaming from room_channel
RoomChannel is transmitting the subscription confirmation
RoomChannel is streaming from room_channel
Here are the relevant files, let me know if I need to share more:
#routes.rb
Rails.application.routes.draw do
mount API::Base, at: '/'
mount ActionCable.server => '/cable/chat'
get 'page/index'
root 'page#index'
end
#page_controller.rb
class PageController < ApplicationController
def index
end
end
I'm trying to get a connection to the websocket simply by curling to the ActionCable server route. Is that possible?
The issue was that I was not sending an Origin header on the http request so allowed_request_origins couldnt match anything. Because of that, it was giving this super obscure error message about not being able to convert the http connection to a websocket one.

How to reduce the frequency of /sidekiq/stats command invocations

How to reduce the frequency of /sidekiq/stats command invocations when the Sidekiq dashboard is kept openend. Is there a way to set the frequency in which the /stats command should be fired.
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:08:59 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:09:04 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:09:10 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:09:14 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:09:20 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:09:24 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:09:30 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:09:34 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:09:39 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:09:44 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:09:50 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:09:54 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:10:00 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:10:04 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:10:09 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:10:14 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:10:19 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:10:24 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:10:29 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:10:34 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:10:39 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:10:44 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:10:49 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:10:54 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:10:59 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:11:04 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:11:09 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:11:14 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:11:19 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:11:24 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:11:29 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:11:34 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:11:39 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:11:44 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:11:49 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:11:54 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:11:59 +0530
Started GET "/sidekiq/stats" for 127.0.0.1 at 2019-01-18 13:12:04 +0530
Do you see the "Polling Interval" slider? Slide it.

how to load multiple files with single HTTP request

In my Rails project, I send a request , these are many files what I need,
Started GET "/assets/bootstrap.min.css?body=1" for 127.0.0.1 at 2015-05-29 11:55:09 +0800
Started GET "/assets/customized_bootstrap.css?body=1" for 127.0.0.1 at 2015-05-29 11:55:09 +0800
Started GET "/assets/jquery.ui.core.css?body=1" for 127.0.0.1 at 2015-05-29 11:55:09 +0800
Started GET "/assets/jquery.ui.theme.css?body=1" for 127.0.0.1 at 2015-05-29 11:55:09 +0800
Started GET "/assets/jquery.ui.accordion.css?body=1" for 127.0.0.1 at 2015-05-29 11:55:09 +0800
Started GET "/assets/jquery.ui.menu.css?body=1" for 127.0.0.1 at 2015-05-29 11:55:09 +0800
Started GET "/assets/jquery.ui.autocomplete.css?body=1" for 127.0.0.1 at 2015-05-29 11:55:09 +0800
Started GET "/assets/jquery.ui.button.css?body=1" for 127.0.0.1 at 2015-05-29 11:55:09 +0800
Started GET "/assets/jquery.ui.datepicker.css?body=1" for 127.0.0.1 at 2015-05-29 11:55:09 +0800
how to load these files via single GET HTTP request ?
This is how the Rails asset pipeline works in the "development" environment. When the app is running in the "production" environment, javascript and css get combined and minified into a single file. Check out the RailsGuide on this topic.

Rails dataTables have to reload page

I'm using dataTables in a Rails app. I have a model called site.
The index for site uses a dataTable to list the sites.
When I first load the index page
http://localhost:3000/sites
The dataTable doesn't work. There are no console errors.
If I reload the page, it works!
During the reload, the console shows entries like this:
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/bootstrap.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/bootstrap-editable.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/ColVis.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/datetimepicker.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/datepicker.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/dataTables/bootstrap/3/jquery.dataTables.bootstrap.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/jquery.qtip.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:30 -0600
Started GET "/assets/jquery.treeTable.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:30 -0600
Started GET "/assets/TableTools.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:30 -0600
Started GET "/assets/TableTools_JUI.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:30 -0600
...
Thanks for the help!
Do you use gem turbolink? If yes, that can be the reason of it, because it do not reload the whole page, just partially. You can solve it in two different ways:
Don't use turbolink (but your website will be slower)
Move your datatable init code into page:change,
like this in application.js:
$(document).on("page:change", function() {
$('#yourtable').dataTable();
});

Rails terminal clogged with loading bootstrap files

I am using Rails 4 and the bootstrap 2 gem (haven't figure out is there is an official / well supported bootstrap 3 gem yet) for my web app.
But the problem is as I'm trying to work through the server logs in my terminal, it is clogged up with a bunch of bootstrap get requests:
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/bootstrap_and_overrides.css?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/messages.css?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/styles.css?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/dataTables/jquery.dataTables.css?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/dataTables/jquery.dataTables.bootstrap.css?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/twitter/bootstrap/bootstrap-alert.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/twitter/bootstrap/bootstrap-modal.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/twitter/bootstrap/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/twitter/bootstrap/bootstrap-transition.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/twitter/bootstrap/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/twitter/bootstrap/bootstrap-popover.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/twitter/bootstrap/bootstrap-tab.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/twitter/bootstrap/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/twitter/bootstrap/bootstrap-button.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/twitter/bootstrap/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/twitter/bootstrap.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/twitter/bootstrap/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/twitter/bootstrap/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/twitter/bootstrap/bootstrap-affix.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/dataTables/jquery.dataTables.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-12-16 13:48:59 -0800
Started GET "/assets/task_sessions.js?body=1" for 127.0.0.1 at 2013-12-16 13:49:00 -0800
Started GET "/assets/tasks.js?body=1" for 127.0.0.1 at 2013-12-16 13:49:00 -0800
Started GET "/assets/welcome.js?body=1" for 127.0.0.1 at 2013-12-16 13:49:00 -0800
Is there any way to not make those things appear for every single request to make debugging and going through the log easier?
Thanks!
There's a gem called quiet_assets which does pretty much what you want.
https://github.com/evrone/quiet_assets
Simply add gem 'quiet_assets', group: :development to your Gemfile and run bundle install
By default it suppresses your assets log messages but you can optionally switch it back on.

Categories

Resources