Why is Heroku not showing my custom header? - ruby-on-rails

I have this code:
response.headers["X-ERROR-MESSAGE"] = "A message"
render :text => "Some text", :status => 400
On my local machine I can get the response headers successfully but when I try it on Heroku, they don't show up. What could be the problem? Is Heroku filtering out my header?
Thanks.

I'll answer my own question. I just asked Heroku support and they said that Heroku makes those headers camel-case. So X-ERROR-MESSAGE will show up as X-Error-Message.

Related

WickedPdf encoding error in only production

I'm novice in rails. I really get in trouble.
Because log isn't tell me what error is it.
I using Korea (UTF-8).
So I set meta tag
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "content-type"}/
and wickedpdf config
format.pdf do
pdf_config
render pdf: "상담 일지-#{ Time.now.strftime("%m-%d %I%p")}.pdf",
layout: 'layouts/application.pdf.haml',
encoding: 'utf8'
end
However
My pdf view in production env is folloing.
However my pdf view in development and staging env is following
I has been googling 5 hour. But It is really strange error. Anyone alse could help me?.....
Anyway, Thank you for listen my question! I hope you solve my problem.

running a link through localhost on a live page

I have an external program running a local API that is set up to play wav files when an endpoint is hit.
In my development environment, it works fine, but when I push to live environment it doesn't work any longer.
Am i missing something?
thanks!
JqueryController
def playfile
require 'json'
HTTParty.get("http://192.168.1.161:5000/play/98")
response = HTTParty.get("http://192.168.1.161:5000/play/#{params[:id]}")
parsed = JSON.parse(response)
#message = params[:message]
Hint.first.update_attributes(message:#message)
if parsed['success'] == true
#success = "Success"
else
#success = "Failed"
end
end
The View
=form_tag("/jquery/playfile", method: 'post', remote:true) do
= label_tag 'hints on the tv!'
= hidden_field_tag :id , 39
=render 'layouts/play'
When I hit the endpoint .. googles inspector is showing a 'pending' request, which eventually dies, and returns an application error response (from heroku)
Im guessing it has something to do with not being allowed to hit a localhost address from a live site..is there a way to get around this?
You cannot access your LAN from the internet (heroku).
If you make a GET on http://192.168.1.161:5000/play/98heroku will search in its own network..
Solution 1:
make a link ().
If you then hit that link from your LAN this would work. (you can use redirect_back if you want to redirect to back to the production site).
Solution 2:
make a tunnel from your http://192.168.1.161:5000/play/98 device.
You can do this with ngrok for example.
Then you would be able to make a GET request with HTTP Party from heroku.
HTTParty.get("http://<ngrok-hash>.ngrok.com/play/98")
NOTE: you need to have a running server on http://192.168.1.161:5000/play/98 for both solutions

Honeybadger on localhost with Ruby on Rails

I've set up Honeybadger almost a year ago and so far it works like a charm registering errors on my production and staging environments.
Then I decided to make a custom error behavior in controller. I am using the code similar to:
begin
params = {
:id => 1,
:class => MyClass,
:foo => "bar"
}
my_unpredicable_method(*params)
rescue => e
Honeybadger.notify(
:error_class => "Special Error",
:error_message => "Special Error: #{e.message}",
:parameters => params
)
end
which is described here.
I was going to test in local environmet to tune error messages, passing params, etc.
But the problem is when I receive the error (I am sure that I receive it, tested with debugger) nothing is sent to honeybadger website. Meanwhile, rake honeybadger:test works fine and sends the testing error messages to the server from localhost. Also, this custom notification works if I push it to testing environment on Heroku.
The question is:
What should I do to send this custom error to honeybadger from localhost?
Thank you in advance.
I found a solution. We need to add the following option to honeybadger initializer:
config.development_environments = %w(test)
This option is the list of environments in which notifications should not be sent and by default development in the list. See detailed explanation of the configuring option here.
Please add following configuration in config/honeybadger.yml
development:
report_data: true
Please read https://github.com/honeybadger-io/honeybadger-ruby#configuration-options

Rails app using Oauth to post to Twitter, getting "not authorized" when running in production server. OK in localhost

I'm trying to use Twitter's Oauth Single Token for posting from a rails app to my twitter feed (single user use-case is perfect for my app). This Is what I'm talking about.
Here's the relevant part of my code:
twitter_consumer_key = 'AAAAAA...'
twitter_consumer_secret = 'BBBBBB///'
oauth_token = 'CCCCC....'
oauth_token_secret = 'DDD.....'
consumer = OAuth::Consumer.new(twitter_consumer_key, twitter_consumer_secret, :site => "http://api.twitter.com", :scheme => :header)
access_token = OAuth::AccessToken.from_hash(consumer, :oauth_token => oauth_token, :oauth_token_secret => oauth_token_secret)
response = access_token.post("http://api.twitter.com/1/statuses/update.json", {:status => "Coffee's ready at 191 Peachtree!! "+Time.now.to_i.to_s})
logger.info response.inspect
When I run this in my local machine, everything goes well and the post is created on my feed. When I run it on my production server (centos5.5, Apache 2, Passenger, Rails 3.0.4) I get "HTTPUnauthorized".
Any ideas on how to troubleshoot this?
Thanks in advance.
Try with filling Callback URL in settings of your application on dev.twitter.com.
Should be something like that:
Callback URL http://yousite.com/auth/twitter/callback
Per abraham's comment, I'm adding the solution as an answer instead of a comment:
My server's timezone was incorrectly set so I was getting the following error in the response body:
{"request":"\/1\/statuses\/update.json","error":"Timestamp out of bounds"}
I set the time and timezone correctly and now it's working fine.
:)

How to set "Connection: close" header in Rails

To fix issues with Safari frequently hanging when uploading files, I need to make a request to my Rails server and have it return an empty body with a "Connection: close" header. More details about this fix can be found here.
So far, I have tried:
def close
return head :ok, {'Connection' => 'close'}
end
def close
response.headers['Connection'] = 'close'
render :nothing => true
end
def close
response.headers['Connection'] = 'close'
return head :ok
end
None of these approaches seem to work. Inspecting the request in Firebug and Safari's developer console reveals that the response header, Connection, is always set to "keep-alive"
I'm running Rails 2.3.5 with Mongrel and Nginx. Setting a header such as Content-Type does work by the way.
Any ideas on how to fix this?
So I never figured out how to do this in Rails, but I did find out that nginx version 0.7.66+ disables keepalive connections for Safari. See the nginx changelog.
So I upgraded my nginx and all is well with Safari now.

Resources