Rails4 - How to delete all messages created using Mailboxer gem? - ruby-on-rails

I followed a tutorial and added messaging functionality in my rails app.
Yesterday, I deleted certain users. Now when I go to my messages link, I get this error message "We're sorry, but something went wrong. If you are the application owner check the logs for more information." which is usually displayed in case of errors.
I saw the log and found out that I must have deleted someone who has sent a message.
I think it's trying to retrieve message of a user that doesn't exist.
ActionView::Template::Error (undefined method `avatar' for nil:NilClass):
How can I solve this issue?
Could anyone please share how to delete all the messages and start fresh? Because the messages are not important.
How do I clear all the mailboxer tables and start fresh? Kindly help.
Here is the log.
2015-05-16T12:17:13.398640+00:00 app[web.1]: Rendered conversations/_participants.html.erb (17.3ms)
2015-05-16T12:17:13.407905+00:00 app[web.1]: CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 2225]]
2015-05-16T12:17:13.434486+00:00 app[web.1]: (16.2ms) SELECT COUNT(*) FROM "mailboxer_receipts" INNER JOIN "mailboxer_notifications" ON "mailboxer_notifications"."id" = "mailboxer_receipts"."notification_id" AND "mailboxer_notifications"."type" IN ('Mailboxer::Message') WHERE "mailboxer_notifications"."conversation_id" = 973 AND "mailboxer_receipts"."receiver_id" = $1 AND "mailboxer_receipts"."receiver_type" = $2 AND "mailboxer_receipts"."trashed" = 'f' AND "mailboxer_receipts"."is_read" = 'f' [["receiver_id", 1464], ["receiver_type", "User"]]
2015-05-16T12:17:13.453617+00:00 app[web.1]: Mailboxer::Receipt Load (1.1ms) SELECT "mailboxer_receipts".* FROM "mailboxer_receipts" WHERE "mailboxer_receipts"."notification_id" = $1 [["notification_id", 1209]]
2015-05-16T12:17:13.456255+00:00 app[web.1]: Rendered conversations/_participants.html.erb (20.5ms)
2015-05-16T12:17:13.474657+00:00 heroku[router]: at=info method=GET path="/conversations" host=www.abc.com request_id=991e2d24-c507-4e5f-9b50-5678e2e3aa2c fwd="160.3.94.130" dyno=web.1 connect=1ms service=276ms status=500 bytes=1786
2015-05-16T12:17:13.569003+00:00 heroku[router]: at=info method=GET path="/speak" host=www.abc.com request_id=c1a056f3-4431-4c90-84b8-01c285e606c1 fwd="122.174.14.148" dyno=web.2 connect=1ms service=37ms status=200 bytes=35624
2015-05-16T12:17:13.459247+00:00 app[web.1]: Mailboxer::Message Load (1.8ms) SELECT "mailboxer_notifications".* FROM "mailboxer_notifications" WHERE "mailboxer_notifications"."type" IN ('Mailboxer::Message') AND "mailboxer_notifications"."conversation_id" = $1 ORDER BY created_at DESC LIMIT 1 [["conversation_id", 782]]
2015-05-16T12:17:13.469138+00:00 app[web.1]: Rendered conversations/_conversation.html.erb (233.8ms)
2015-05-16T12:17:13.469485+00:00 app[web.1]: Rendered conversations/index.html.erb within layouts/application (249.4ms)
2015-05-16T12:17:13.469543+00:00 app[web.1]: Completed 500 Internal Server Error in 261ms
2015-05-16T12:17:13.473924+00:00 app[web.1]:
2015-05-16T12:17:13.473928+00:00 app[web.1]: ActionView::Template::Error (undefined method `avatar' for nil:NilClass):
2015-05-16T12:17:13.473930+00:00 app[web.1]: 16:
2015-05-16T12:17:13.473932+00:00 app[web.1]: 17: <span class="messageuser">
2015-05-16T12:17:13.473933+00:00 app[web.1]: 18: <%#= conversation.last_message.sender.name %>
2015-05-16T12:17:13.473936+00:00 app[web.1]: 19: <%= link_to image_tag(conversation.last_message.sender.avatar.url(:mini), class: 'img-rounded'), user_path(conversation.last_message.sender) %>
2015-05-16T12:17:13.473944+00:00 app[web.1]: 20: <%= link_to conversation.last_message.sender.name, user_path(conversation.last_message.sender) %>
2015-05-16T12:17:13.473946+00:00 app[web.1]: 21: </span>
2015-05-16T12:17:13.473948+00:00 app[web.1]: 22:
2015-05-16T12:17:13.473951+00:00 app[web.1]: app/views/conversations/_conversation.html.erb:19:in `_app_views_conversations__conversation_html_erb___2085506579815819501_69959535266760'
2015-05-16T12:17:13.473952+00:00 app[web.1]: app/views/conversations/index.html.erb:35:in `_app_views_conversations_index_html_erb___1748297580391940998_69959535151580'
2015-05-16T12:17:13.473954+00:00 app[web.1]:
2015-05-16T12:17:13.473957+00:00 app[web.1]:
2015-05-16T12:17:13.572052+00:00 app[web.1]: Started GET "/conversations" for 160.3.94.130 at 2015-05-16 12:17:13 +0000
2015-05-16T12:17:13.579974+00:00 app[web.1]: User Load (1.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1464]]
2015-05-16T12:17:13.585203+00:00 app[web.1]: (0.9ms) SELECT COUNT(*) FROM "user_learnings" WHERE "user_learnings"."user_id" = $1 [["user_id", 1464]]
2015-05-16T12:17:13.637517+00:00 app[web.1]: (3.1ms) SELECT DISTINCT COUNT(DISTINCT "mailboxer_conversations"."id") FROM "mailboxer_conversations" INNER JOIN "mailboxer_notifications" ON "mailboxer_notifications"."conversation_id" = "mailboxer_conversations"."id" AND "mailboxer_notifications"."type" IN ('Mailboxer::Message') INNER JOIN "mailboxer_receipts" ON "mailboxer_receipts"."notification_id" = "mailboxer_notifications"."id" WHERE "mailboxer_notifications"."type" = 'Mailboxer::Message' AND "mailboxer_receipts"."receiver_id" = $1 AND "mailboxer_receipts"."receiver_type" = $2 AND "mailboxer_receipts"."mailbox_type" = $3 AND "mailboxer_receipts"."trashed" = 'f' AND "mailboxer_receipts"."deleted" = 'f' [["receiver_id", 1464], ["receiver_type", "User"], ["mailbox_type", "inbox"]]
2015-05-16T12:17:13.678884+00:00 app[web.1]: Mailboxer::Receipt Load (1.2ms) SELECT "mailboxer_receipts".* FROM "mailboxer_receipts" WHERE "mailboxer_receipts"."notification_id" = $1 [["notification_id", 1443]]
2015-05-16T12:17:13.698778+00:00 app[web.1]: User Load (4.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1464]]
2015-05-16T12:17:13.464477+00:00 app[web.1]: User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1937]]

I grew impatient and destroyed them all.
irb(main):002:0> Mailboxer::Conversation.destroy_all
Now the errors are gone and I am able to send messages.
I didn't know how to delete the conversations of 800 users I deleted recently.

You are right. The application is calling methods on users that do not exist. For example:
```
<%= link_to conversation.last_message.sender.name...
(conversation.last_message) is saved, but sender does not exist.
If you want to start the database from scratch you can run (rake db:reset), that will drop create and migrate your database.
To solve the issue create a method that runs every time a user cancels or deletes his/her account, and that it deletes that user's conversations.
Try this is your console (rails c), it will delete the first user's conversations.
```
User.first.mailbox.conversations.each do |i| i.delete end
If you still want to show the conversation to the other user who did not canceled his account. You have to save that name somewhere else or show the user that the sender deleted his account.
```
<% if conversation.sender == null %>
<%= conversation.last_message %>
<p>User of this conversation deleted his/her account</p>
<%else%>
<%= conversation.last_message %>
<%= conversation.last_message.sender.name %>
<% end %>

Sounds like one unoptimized way to do it would be loop through on the model that has messaging functionality added to it with acts_as_messageable..like MyModel.each do |mod| mod.mailbox.conversations.destroy_all end

Related

Rails: User info not updating (Rendered ActiveModel Serializer Null with Hash)

The same code is working in the local but not working in Heroku
def update
current_user.update!(user_params)
response = { message: Message.account_updated}
json_response(response)
end
private
def user_params
params.permit(:first_name, :last_name, :email, :password)
end
routes.rb
namespace :api do
namespace :v1 do
put 'user/update', to: 'users#update'
end
end
user_serializer.rb
class UserSerializer < ActiveModel::Serializer
attributes :id, :username, :first_name, :last_name, :email, :created_at, :updated_at
end
that is my and it's working on my local via Postman, that is for updating user info, but while I push to Heroku and try to update via Postman then not working, log showing like this
2018-04-30T10:15:47.665731+00:00 heroku[router]: at=info method=PUT path="/api/v1/user/update?first_name=John&last_name=Doe" host=my-host.herokuapp.com request_id=79a84b63-be87-46f8-8fad-2d151a63722f fwd="27.147.231.22" dyno=web.1 connect=0ms service=18ms status=500 bytes=283 protocol=https
2018-04-30T10:15:47.648979+00:00 app[web.1]: [79a84b63-be87-46f8-8fad-2d151a63722f] Started PUT "/api/v1/user/update?first_name=John&last_name=Doe"
for 27.147.231.22 at 2018-04-30 10:15:47 +0000
2018-04-30T10:15:47.650866+00:00 app[web.1]: [79a84b63-be87-46f8-8fad-2d151a63722f] Processing by Api::V1::UsersController#update as */*
2018-04-30T10:15:47.650987+00:00 app[web.1]: [79a84b63-be87-46f8-8fad-2d151a63722f] Parameters: {"first_name"=>"John", "last_name"=>"Doe"}
2018-04-30T10:15:47.654619+00:00 app[web.1]: [79a84b63-be87-46f8-8fad-2d151a63722f] User Load (1.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
2018-04-30T10:15:47.656446+00:00 app[web.1]: [79a84b63-be87-46f8-8fad-2d151a63722f] CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
2018-04-30T10:15:47.658345+00:00 app[web.1]: [79a84b63-be87-46f8-8fad-2d151a63722f] (1.1ms) BEGIN
2018-04-30T10:15:47.661446+00:00 app[web.1]: [79a84b63-be87-46f8-8fad-2d151a63722f] User Exists (1.2ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER($1) AND "users"."id" != $2 LIMIT $3 [["email", "j#gmail.com"], ["id", 1], ["LIMIT", 1]]
2018-04-30T10:15:47.663630+00:00 app[web.1]: [79a84b63-be87-46f8-8fad-2d151a63722f] (1.0ms) COMMIT
2018-04-30T10:15:47.664737+00:00 app[web.1]: [79a84b63-be87-46f8-8fad-2d151a63722f] [active_model_serializers] Rendered ActiveModel::Serializer::Null with Hash (0.51ms)
2018-04-30T10:15:47.665015+00:00 app[web.1]: [79a84b63-be87-46f8-8fad-2d151a63722f] Completed 500 Internal Server Error in 14ms (Views: 1.1ms | ActiveRecord: 4.5ms)
I think that's the problem
Rendered ActiveModel::Serializer::Null with Hash (0.51ms)
But I don't understand what's going on.
Update
module Response
def json_response(object, status = :ok)
render json: object, status: status
end
end
First of all
Rendered ActiveModel::Serializer::Null with Hash (0.51ms)
That's not the issue for not updating user info, it's showing in the log because ActiveModel::Serializer serialize the columns which have null value.
I think the problem is elsewhere like you need to refactor why causes this e.g you can try to remove ! update!(user_params) try like this current_user.update(user_params) or any other.
# place this method inside NullAttributesRemover or directly inside serializer class
def serializable_hash(adapter_options = nil, options = {}, adapter_instance = self.class.serialization_adapter_instance)
hash = super
hash.each { |key, value| hash.delete(key) if value.nil? }
hash
end
it will serialize columns which have only real values.
I think it will help.

Cart/Checkout ActiveRecord::InvalidForeignKey (PG::ForeignKeyViolation: ERROR on Heroku but not Localhost

have a working cart/checkout functionality on my app which works perfectly fine on localhost, but when I deploy to Heroku items don't get added to the cart when the "Add to Cart" button is clicked.
The Heroku logs show this for the error:
2017-05-19T21:12:00.506230+00:00 app[web.1]: Started POST "/order_items" for 68.225.227.137 at 2017-05-19 21:12:00 +0000
2017-05-19T21:12:00.508991+00:00 app[web.1]: Processing by OrderItemsController#create as JS
2017-05-19T21:12:00.511223+00:00 app[web.1]: User Load (0.8ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
2017-05-19T21:12:00.509041+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "order_item"=>{"quantity"=>"1", "product_id"=>"2"}, "commit"=>"Add to Cart"}
2017-05-19T21:12:00.516450+00:00 app[web.1]: Product Load (0.7ms) SELECT "products".* FROM "products" WHERE "products"."active" = $1 AND "products"."id" = $2 LIMIT 1 [["active", "t"], ["id", 2]]
2017-05-19T21:12:00.513630+00:00 app[web.1]: (0.6ms) BEGIN
2017-05-19T21:12:00.531537+00:00 app[web.1]: SQL (12.8ms) INSERT INTO "orders" ("user_id", "subtotal", "created_at", "updated_at", "order_status_id") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["user_id", 1], ["subtotal", "499.0"], ["created_at", "2017-05-19 21:12:00.517193"], ["updated_at", "2017-05-19 21:12:00.517193"], ["order_status_id", 1]]
2017-05-19T21:12:00.532478+00:00 app[web.1]: (0.8ms) ROLLBACK
2017-05-19T21:12:00.533488+00:00 app[web.1]:
2017-05-19T21:12:00.532671+00:00 app[web.1]: Completed 500 Internal Server Error in 24ms (ActiveRecord: 15.8ms)
2017-05-19T21:12:00.533491+00:00 app[web.1]: DETAIL: Key (order_status_id)=(1) is not present in table "order_statuses".
2017-05-19T21:12:00.533490+00:00 app[web.1]: ActiveRecord::InvalidForeignKey (PG::ForeignKeyViolation: ERROR: insert or update on table "orders" violates foreign key constraint "fk_rails_7a22cf8b0e"
2017-05-19T21:12:00.533492+00:00 app[web.1]: : INSERT INTO "orders" ("user_id", "subtotal", "created_at", "updated_at", "order_status_id") VALUES ($1, $2, $3, $4, $5) RETURNING "id"):
2017-05-19T21:12:00.533493+00:00 app[web.1]: app/controllers/order_items_controller.rb:7:in `create'
2017-05-19T21:12:00.533494+00:00 app[web.1]:
2017-05-19T21:12:00.533495+00:00 app[web.1]:
2017-05-19T21:12:06.465383+00:00 heroku[router]: at=info method=POST path="/order_items" host=aloop-offroad.herokuapp.com request_id=b13e7b04-7ac0-44fe-b58f-a850ce4cd7e8 fwd="68.225.227.137" dyno=web.1 connect=0ms service=16ms status=500 bytes=1754 protocol=http
Can anyone see what's happening? I'm lost because I can't see anything that would work on localhost but not Heroku.
Your error is, boiled down, that you're trying to insert a record into orders with a value for order_status_id that violates a constraint. This is probably because you seeded your database locally with a few OrderStatus objects and hardcoded their ids into your code. Those records don't exist in your production database, though. You should probably update your code to pull the order status options from the database on request, and then create the relevant status records in your production database.

Rails app on Heroku status 500 internal server error (We're sorry but something went wrong)

Hello so I have an app that works great locally but as soon as I pushed it to Heroku I'm having issues.
HEROKU LINK: https://sleepy-garden-73993.herokuapp.com
GITHUB REPO: https://github.com/kbachand/ginger_ails
ERROR IN CONSOLE WHEN INSPECT THE PAGE:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
HOW TO DUPLICATE ISSUE:
-Click "check your address", ENTER address: 202 tryon st; ZIP code: 28207 (this is in our service area)
-Click "select your ailment" and select one (any will work)
-Click "purchase remedy kit", and it will prompt you to login or sign up. You can sign up if you'd like but my login is keithbtest#gmail.com and password: surfsup714
-Once you login click "purchase remedy kit" and it SHOULD render a view that shows you all the items in the cart and allows you to empty or purchase via stripe. But instead you get the error.
HEROKU LOG:
2016-11-02T18:15:02.693028+00:00 app[web.1]: [1m[36mCart Load (1.4ms)[0m [1mSELECT "carts".* FROM "carts" WHERE "carts"."id" = $1 LIMIT 1[0m [["id", 1]]
2016-11-02T18:15:02.696486+00:00 app[web.1]: ActiveRecord::StatementInvalid (PG::DatatypeMismatch: ERROR: argument of WHERE must be type boolean, not type integer
2016-11-02T18:15:02.695276+00:00 app[web.1]: [1m[35mUser Load (1.8ms)[0m SELECT "users".* FROM "users" WHERE (1) LIMIT 1
2016-11-02T18:15:02.695572+00:00 app[web.1]: Completed 500 Internal Server Error in 7ms (ActiveRecord: 4.6ms)
2016-11-02T18:15:02.696484+00:00 app[web.1]:
2016-11-02T18:15:02.696487+00:00 app[web.1]: ^
2016-11-02T18:15:02.696486+00:00 app[web.1]: LINE 1: SELECT "users".* FROM "users" WHERE (1) LIMIT 1
2016-11-02T18:15:02.696488+00:00 app[web.1]: : SELECT "users".* FROM "users" WHERE (1) LIMIT 1):
2016-11-02T18:15:02.696488+00:00 app[web.1]: app/controllers/carts_controller.rb:35:in `show'
2016-11-02T18:15:02.696489+00:00 app[web.1]:
2016-11-02T18:15:02.696489+00:00 app[web.1]:
2016-11-02T18:18:42.858131+00:00 heroku[router]: at=info method=GET path="/" host=sleepy-garden-73993.herokuapp.com request_id=5c66a6cc-7de8-43b6-92c3-51b63a3d3ab7 fwd="104.139.26.81" dyno=web.1 connect=1ms service=18ms status=200 bytes=6966
The important bits on the log are:
"ActiveRecord::StatementInvalid (PG::DatatypeMismatch: ERROR: argument of WHERE must be type boolean, not type integer "
Below it reads the error is on app/controllers/carts_controller.rb:35
https://github.com/kbachand/ginger_ails/blob/master/app/controllers/carts_controller.rb#L35
On that line you have:
#user = User.find_by(id: params[:id])
So it looks like params[:id] is an integer, but the id column is a boolean.
When looking at your schema.rb to check your column types, I realized you have the devise gem installed, so you should use devise's helpers to authenticate the user instead of doing it manually:
https://github.com/plataformatec/devise#controller-filters-and-helpers
Let me know if that helps!

Heroku website rails cant log in

Hi everyone I had a website working on localhost:3000 and after deploying it to heroku it wont log in either through email, facebook or google.
It says...
We're sorry, but something went wrong.
If you are the application owner check the logs for more information.
This is the log, as far as I am aware.
2016-07-27T14:19:43.719220+00:00 app[web.1]: Started GET "/auth/facebook" for 178.167.254.130 at 2016-07-27 14:19:43 +0000
2016-07-27T14:19:44.385948+00:00 app[web.1]: User Load (2.0ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["email", "barryjamesreeves#gmail.com"]]
2016-07-27T14:19:44.376866+00:00 app[web.1]: Parameters: {"code"=>"AQAimEd3zlA9aomiPb115KoKJ9ntclITq7BNYfEz8VezLOAIBry-mSaGF2zbFL0hkz2g7l_YS7fdK89AuFQ7CeQoF7O42hEk8jEcvAfeJl9UeeQu-QiAF5RO8y1YcMhfj4HEOrXjVXuXT_vY0GSQQ15ZUAVaByR6H8aPwtRcDZnyS2orAi36gew0gP1aG3qGsxGlIIDt6o_LShm--zog3twAbFe4vHLXSJtdWxdG_G4pMCBv5oqzq84mS7avF0qDlXOGS5HfGcyODFlbh8t1rqjMXJNCUVBm-7J0WLMvncTQTawuhRQAvJAWJRr7WDCEYXu4SUsvOAxvzQ5KrfECE4Ji", "state"=>"84f33935f2d2f759cbf1b9bb5025bfdbfba95bb82f9972a1"}
2016-07-27T14:19:44.483905+00:00 app[web.1]: User Exists (1.8ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = 'barryjamesreeves#gmail.com' LIMIT 1
2016-07-27T14:19:44.390107+00:00 app[web.1]: User Load (1.6ms) SELECT "users".* FROM "users" WHERE "users"."provider" = $1 AND "users"."uid" = $2 ORDER BY "users"."id" ASC LIMIT 1 [["provider", "facebook"], ["uid", "638781552953110"]]
2016-07-27T14:19:44.376844+00:00 app[web.1]: Processing by OmniauthCallbacksController#facebook as HTML
2016-07-27T14:19:44.250584+00:00 app[web.1]: Started GET "/auth/facebook/callback?code=AQAimEd3zlA9aomiPb115KoKJ9ntclITq7BNYfEz8VezLOAIBry-mSaGF2zbFL0hkz2g7l_YS7fdK89AuFQ7CeQoF7O42hEk8jEcvAfeJl9UeeQu-QiAF5RO8y1YcMhfj4HEOrXjVXuXT_vY0GSQQ15ZUAVaByR6H8aPwtRcDZnyS2orAi36gew0gP1aG3qGsxGlIIDt6o_LShm--zog3twAbFe4vHLXSJtdWxdG_G4pMCBv5oqzq84mS7avF0qDlXOGS5HfGcyODFlbh8t1rqjMXJNCUVBm-7J0WLMvncTQTawuhRQAvJAWJRr7WDCEYXu4SUsvOAxvzQ5KrfECE4Ji&state=84f33935f2d2f759cbf1b9bb5025bfdbfba95bb82f9972a1" for 178.167.254.130 at 2016-07-27 14:19:44 +0000
2016-07-27T14:19:44.480409+00:00 app[web.1]: (1.6ms) BEGIN
2016-07-27T14:19:44.252793+00:00 app[web.1]: I, [2016-07-27T14:19:44.252730 #3] INFO -- omniauth: (facebook) Callback phase initiated.
2016-07-27T14:19:44.688539+00:00 app[web.1]: User Load (1.7ms) SELECT "users".* FROM "users" WHERE "users"."provider" = $1 AND "users"."uid" = $2 AND "users"."confirmation_token" = $3 ORDER BY "users"."id" ASC LIMIT 1 [["provider", "facebook"], ["uid", "638781552953110"], ["confirmation_token", "7e801f409f1a87a3e65cb42cc124e971ec3e7f7caf4f441795985c6d9110969a"]]
2016-07-27T14:19:44.693755+00:00 app[web.1]: SQL (1.7ms) INSERT INTO "users" ("provider", "uid", "fullname", "email", "image", "encrypted_password", "created_at", "updated_at", "confirmation_token", "confirmation_sent_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "id" [["provider", "facebook"], ["uid", "638781552953110"], ["fullname", "Barry Reeves"], ["email", "barryjamesreeves#gmail.com"], ["image", "http://graph.facebook.com/638781552953110/picture"], ["encrypted_password", "$2a$10$LnDgeb0oc.2oczdFwYeizeX2tuQDoC8aF.jJ02ddBSM8wxlhxzaZy"], ["created_at", "2016-07-27 14:19:44.484330"], ["updated_at", "2016-07-27 14:19:44.484330"], ["confirmation_token", "SzgGE4Z67As_h-fdmXgR"], ["confirmation_sent_at", "2016-07-27 14:19:44.688985"]]
2016-07-27T14:19:44.734814+00:00 app[web.1]: Rendered devise/mailer/confirmation_instructions.html.erb (1.9ms)
2016-07-27T14:19:44.734891+00:00 app[web.1]:
2016-07-27T14:19:44.734893+00:00 app[web.1]: Devise::Mailer#confirmation_instructions: processed outbound mail in 38.3ms
2016-07-27T14:19:44.736688+00:00 app[web.1]: (1.6ms) ROLLBACK
2016-07-27T14:19:44.738075+00:00 app[web.1]: Completed 500 Internal Server Error in 361ms (ActiveRecord: 13.8ms)
2016-07-27T14:19:44.740664+00:00 app[web.1]:
2016-07-27T14:19:44.740666+00:00 app[web.1]: ActionView::Template::Error (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):
2016-07-27T14:19:44.740667+00:00 app[web.1]: 2:
2016-07-27T14:19:44.740667+00:00 app[web.1]: 3: You can confirm your account email through the link below:
2016-07-27T14:19:44.740668+00:00 app[web.1]: 4:
2016-07-27T14:19:44.740669+00:00 app[web.1]: 5: <%= link_to 'Confirm my account', confirmation_url(#resource, confirmation_token: #token) %>
2016-07-27T14:19:44.740670+00:00 app[web.1]: app/views/devise/mailer/confirmation_instructions.html.erb:5:in _app_views_devise_mailer_confirmation_instructions_html_erb__4041444012376916285_69837330575780'
2016-07-27T14:19:44.740671+00:00 app[web.1]: app/models/user.rb:20:infrom_omniauth'
2016-07-27T14:19:44.740671+00:00 app[web.1]: app/controllers/omniauth_callbacks_controller.rb:4:in `facebook'
2016-07-27T14:19:44.740672+00:00 app[web.1]:
2016-07-27T14:19:44.740673+00:00 app[web.1]:
2016-07-27T14:19:37.167494+00:00 heroku[router]: at=info method=GET path="/" host=gentle-escarpment-62627.herokuapp.com request_id=02fbf786-95af-4421-ae32-ae221c0ea302 fwd="178.167.254.130" dyno=web.1 connect=0ms service=88ms status=200 bytes=5829
Any help appreciated
thanks

How do I see detailed logs in Heroku, similar to the logs I see in my dev environment?

In my dev environment, when I make a request on my app, I see the AREL & SQL queries like this:
Started GET "/products/20" for 127.0.0.1 at 2012-12-31 19:18:40 -0500
Processing by ProductsController#show as HTML
Parameters: {"id"=>"20"}
Category Load (0.2ms) SELECT "categories".* FROM "categories" LIMIT 6
Product Load (0.1ms) SELECT "products".* FROM "products" WHERE "products"."id" = ? LIMIT 1 [["id", "20"]]
Product Load (0.3ms) SELECT "products".* FROM "products"
Vendor Load (0.2ms) SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" = 11 LIMIT 1
Product Load (0.2ms) SELECT "products".* FROM "products" WHERE "products"."vendor_id" = 11
(0.2ms) SELECT COUNT(*) FROM "categories" INNER JOIN "category_products" ON "categories"."id" = "category_products"."category_id" WHERE "category_products"."product_id" = 20
Category Load (0.1ms) SELECT "categories".* FROM "categories" INNER JOIN "category_products" ON "categories"."id" = "category_products"."category_id" WHERE "category_products"."product_id" = 20
CACHE (0.0ms) SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" = 11 LIMIT 1
CACHE (0.0ms) SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" = 11 LIMIT 1
Rendered products/_similar_products.html.erb (6.1ms)
Rendered products/show.html.erb within layouts/application (71.2ms)
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
(0.2ms) SELECT COUNT(*) FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = 1 AND (((roles.name = 'superadmin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))
Rendered layouts/_login_nav.html.erb (5.1ms)
Rendered layouts/_navigation.html.erb (0.9ms)
Rendered layouts/_header.html.erb (76.4ms)
Rendered layouts/_messages.html.erb (0.3ms)
Rendered layouts/_footer.html.erb (0.1ms)
Completed 200 OK in 1171ms (Views: 1160.9ms | ActiveRecord: 1.9ms)
But this is the same query on Heroku:
2013-01-01T00:24:57+00:00 app[web.1]: Started GET "/products/20" for 67.230.41.62 at 2013-01-01 00:24:57 +0000
2013-01-01T00:24:58+00:00 heroku[router]: at=info method=GET path=/products/20 host=myapp.herokuapp.com fwd=67.230.41.62 dyno=web.1 queue=0 wait=0ms connect=1ms service=59ms status=200 bytes=7718
I am tailing my Heroku logs by doing heroku logs --tail, that's how I am getting that info.
Is it possible to get the same type of logs that I see in my dev environment on Heroku?
Thanks.
Edit:
In my config/environment.rb I put this:
ActiveRecord::Base.logger.level = Logger::DEBUG
In config/environment/production.rb I put this:
config.log_level = :debug
On older stacks, Heroku inserts a plugin into your app that reconfigures the logger to fit into Heroku's setup. This plugin uses the LOG_LEVEL environment variable to set the logging level used (whatever is in your app's config is ignored)
Update that environment variable to DEBUG and you should see the extra info.
With current stacks, you should use the rails_12factor gem, that redirects log output to stdout, where Heroku expects to find it.
There's a log_level setting in the per environment initializers ({development,staging,production}.rb). In production and staging it is either commented or set to :info. Set it to :debug.
Also, add
ActiveRecord::Base.logger.level = Logger::DEBUG
to the bottom of your config/environment.rb.
Add the following to production.rb
config.logger = Logger.new(STDOUT)

Resources