Can't open rails app, even if server is running - ruby-on-rails

I've been developing a rails app with a VM and vagrant. Until yesterday, everything was working fine. However, when I tried to run the server and open the browser, it wasn't working. I tried on Chrome, Firefox and Safari, but the error persists on all three. I checked my dev logs, and this is what it says.
Yesterday's log:
Started GET "/" for 10.0.2.2 at 2013-12-11 06:38:31 +0000 Processing by HomeController#index as HTML Rendered home/index.html.erb within layouts/application (43.6ms) Completed 200 OK in 159ms (Views: 158.0ms | ActiveRecord: 0.0ms)
and today's log says:
Started GET "/" for 127.0.0.1 at 2013-12-12 19:02:04 +0000
[1m[36mActiveRecord::SchemaMigration Load (1.4ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
Processing by HomeController#index as */*
Rendered home/index.html.erb within layouts/application (212.7ms)
Completed 200 OK in 595ms (Views: 555.4ms | ActiveRecord: 0.0ms)
[1m[36mActiveRecord::SchemaMigration Load (1.5ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
Could anyone explain why the address it's trying to connect to appears to be different? And what needs to be done in order to be able to connect to it again?
Thanks.

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.

Can't login with devise on heroku, all other environments work

I got an app that runs fine locally and on production (deployed with capistrano) and I'm trying to set up a staging environment which worked so far except for devise.
When I try to log in with working user credentials I get redirected to the root path but not logged in.
Logs:
Started POST "/login" for 95.91.228.167 at 2016-01-31 13:33:51 +0000
Processing by PagesController#index as HTML
Rendered shared/_sidebar.html.erb (0.2ms)
Completed 200 OK in 2.7ms (Views: 2.1ms | ActiveRecord: 0.0ms)
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"iHo8UfHuZ9S6GVbj3hAvfzqwo67FfZwZtdhwJ2qTk3Q=", "user"=>{"email"=>"xxx#xxx.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Einloggen"}
WARNING: Can't verify CSRF token authenticity
Redirected to http://xxx.herokuapp.com/
Completed 302 Found in 81.5ms (ActiveRecord: 0.0ms)
Started GET "/" for 95.91.228.167 at 2016-01-31 13:33:51 +0000
Rendered pages/index.html.erb within layouts/application (0.5ms)
I tried all solutions posted here like changing the domain in session_store and I updated devise to the most recent version.
Any ideas? If you need more information, please let me know.
As it turned out session_store.rb had domain: :all which I thought was fine. Once I changed it to xxx.herokuapp.com, it worked. Thanks!
--- Update 1 ---
Now that it works on heroku, it doesn't work on the production server anymore - obviously because of the wrong URL in session_store. What to do now?
--- Update 2 ---
Solved this by using environment variables

Unknown slow process of requests

The behaviour is: the browser hangs keep loading without any response back.
Please see the following log.
I, [2014-07-16T14:14:09.766062 #11713] INFO -- : Started GET "/somepage" for xxx.xxx.xxx.xxx at 2014-07-16 14:14:09 +0800
I, [2014-07-16T14:14:40.872411 #31111] INFO -- : Started GET "/" for yyy.yyy.yyy.yyy at 2014-07-16 14:14:40 +0800
I, [2014-07-16T14:14:40.874968 #31111] INFO -- : Processing by HomeController#index as */*
I, [2014-07-16T14:14:40.893189 #31111] INFO -- : Rendered ...
I, [2014-07-16T14:14:40.901553 #31111] INFO -- : Completed 200 OK in 26ms (Views: 22.5ms | ActiveRecord: 2.6ms)
... more other requests handled normally
I, [2014-07-16T14:29:35.395493 #11713] INFO -- : Processing by HomeController#somepage as HTML
I, [2014-07-16T14:29:35.403614 #11713] INFO -- : Rendered home/somepage.html.erb (1.5ms)
I, [2014-07-16T14:29:35.403762 #11713] INFO -- : Completed 200 OK in 8ms (Views: 5.0ms | ActiveRecord: 0.5ms)
In between the "Started GET ..." and "Processing by" logs, the rails app can handle other requests normally. However, the 2 logs (should be from the same request) have around 15mins gap.
Server: Apache with passenger
Database: Mysql using mysql2 adapter
I completely lost and have no clues what is the root cause....
I faced this similar kind of issue where the browser kept on loading with no logs in the log file.And what i found out was that we have mistakenly written find.all in one of our model as during testing it only had 1000 records as compared to production with more than 1 million records.so changing it to batch records/pagination resolved it.
...........Hope this might help you.

ActiveRecord::StatementInvalid (Could not find table)

I've got a rails application on DigitalOcean. I'm using the Comfortable Mexican Sofa CMS. I added the gem and ran rails generate comfy:cms and rake db:migrate but when I navigate to example.com/admin, I get a 500 error and my application isn't able to find the necessary tables. Here's the error I get in the logs.
I, [2014-06-24T21:51:18.397255 #18789] INFO -- : Started GET "/" for 173.10.20.190 at 2014-06-24 21:51:18 +0000
I, [2014-06-24T21:51:18.425183 #18789] INFO -- : Processing by HomeController#index as HTML
I, [2014-06-24T21:51:18.442366 #18789] INFO -- : Rendered home/index.html.erb within layouts/application (1.2ms)
I, [2014-06-24T21:51:18.445116 #18789] INFO -- : Completed 200 OK in 20ms (Views: 9.5ms | ActiveRecord: 0.0ms)
I, [2014-06-24T21:51:18.599085 #18786] INFO -- : Started GET "/assets/rails.png" for 173.10.20.190 at 2014-06-24 21:51:18 +0000
I, [2014-06-24T21:51:23.516755 #18789] INFO -- : Started GET "/admin" for 173.10.20.190 at 2014-06-24 21:51:23 +0000
I, [2014-06-24T21:51:23.522184 #18789] INFO -- : Processing by Comfy::Admin::Cms::BaseController#jump as HTML
I, [2014-06-24T21:51:23.526053 #18789] INFO -- : Completed 500 Internal Server Error in 4ms
F, [2014-06-24T21:51:23.532357 #18789] FATAL -- :
ActiveRecord::StatementInvalid (Could not find table 'comfy_cms_sites'):
What seems strange to me is that when I run rails c and ActiveRecord::Base.connection.tables, the tables show up and 'comfy_cms_sites' is there.
Make sure you've run your migrations on your production db with
rake db:migrate RAILS_ENV=production

Empty HTML in production

Rails is returning blank HTML when running in production.
The tests I describe bellow are done with the following line: wget http://localhost:3000/login -O here.txt ; cat here.txt. I expect see some HTML being output after executing it.
On my server, I can see the HTML being rendered when I start rails in development mode, using the command rails s. I can see the following in the log:
Started GET "/login" for 127.0.0.1 at 2013-08-21 18:30:32 +0000
Processing by UserSessionsController#new as */*
Rendered user_sessions/_login.html.haml (59.5ms)
Rendered user_sessions/new.html.haml within layouts/application (62.8ms)
Compiled bootstrap-datepicker.css (0ms) (pid 8050)
Compiled application.css (4ms) (pid 8050)
Compiled bootstrap.min.css (0ms) (pid 8050)
# lots of Compiled lines
Rendered layouts/_navigation.html.haml (3.2ms)
Rendered layouts/_messages.html.haml (1.0ms)
Completed 200 OK in 1404ms (Views: 1395.6ms | ActiveRecord: 0.8ms)
When starting my application with RAILS_ENV=production rails s, doing the same request, I got the following on the log:
Started GET "/login" for 127.0.0.1 at 2013-08-21 18:30:52 +0000
Processing by UserSessionsController#new as */*
Rendered user_sessions/_login.html.haml (57.8ms)
Rendered user_sessions/new.html.haml within layouts/application (60.9ms)
Completed 200 OK in 69ms (ActiveRecord: 0.9ms)
But no HTML is output. What is happening? Why this is not working the same way that it does on development?
I use rails 3.2.13, and in this test it runs with WEBrick. I also am using RVM if that matters.
Update: Using the content of config/environments/development.rb on config/environments/production.rb does not fix the problem
The problem is that I was rescuing an exception on ApplicationController and not handling it properly by a logical error. The exception was not raised on development mode.

Resources