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.
Related
Due to business requirements, I need to create a new sitemap, every time a new page is added in the admin panel. We're using Heroku, so we looked into the sitemap_generator gem to do this. We are uploading the sitemap every time the rake sitemap:refresh is called.
But the sitemap needs to be inside our domain such as https://example.org/sitemap.xml. So we decided to use reverse proxy (with rack-reverse-proxy gem)
in our config.ru we have
use Rack::ReverseProxy do
reverse_proxy '/sitemap.xml', 'http://our-bucket.amazonaws.com/sitemaps/sitemap.xml', :timeout => 15000, :preserve_host => true
end
and our robots.txt file is
User-Agent: *
Allow: /
Disallow: /admin
But when we submit in google webmaster tools, I get an error, saying URL restricted by robots.txt, when I try to access directly in the browser https://our_domain.com/sitemap.xml I get an
<Error>
<Code>InvalidArgument</Code>
<Message>Unsupported Authorization Type</Message>
<ArgumentName>Authorization</ArgumentName>
but accessing the s3 link, http://our-bucket.s3.amazonaws.com/sitemaps/sitemap.xml our sitemap.xml is displayed correctly.
Any ideas? Is what we're attempting to do even possible?
Ran into this same issue because I was on a system that was behind Basic Auth, and so it was passing along that header, which S3 did not like.
Resolved mine by updating reverse_proxy to this latest commit (for some reason the setting I needed didn't make it into the latest release tag):
gem 'rack-reverse-proxy', require: 'rack/reverse_proxy', git: 'https://github.com/waterlink/rack-reverse-proxy.git', ref: 'a4f28a6'
and adding the following setting to reverse_proxy:
config.middleware.use Rack::ReverseProxy do
reverse_proxy_options stripped_headers: ['Authorization']
... <rules here>
end
This question was old but hopefully this helps someone in the future.
You could create an action that responds as xml like so app/controllers/sitemap_controller.rb:
layout false
def index
#my_pages = Pages.all
render formats: :xml
end
And correspondent view file app/views/sitemap/index.xml.builder:
base_url = request.url.chomp('sitemap.xml')
xml.instruct! :xml, version: '1.0', encoding: 'utf-8'
xml.tag! 'urlset',
'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9',
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation' => 'http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd' do
#my_pages.each do |page|
xml.url {
xml.loc URI.join(base_url, page.url)
}
end
end
Don't forget to create a route for it:
config/routes.rb:
get '/sitemap.xml', to: 'sitemap#index'
No need for reverse proxy, you could also create an rake task to ping search engines and you're good to go.
Happy coding!
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
I have a production machine that is your basic CentOS machine on Amazon AWS, nothing special there.
I am essentially running this:
#digest = WeeklyDigest.most_recent.first
#mailer = DigestMailer.weekly_digest(#digest)
#mailchimp = MailChimp.new
#mailchimp.new_digest(#mailer.body.to_s)
What this code does is finds my latest weekly_digest, generate a new mailer using that, and then I grab the html from that and send it to mailchimp.
I have a weekly_digest.html.slim in app/views/digest_mailer and I have a digest_mailer.html.slim in app/views/layouts.
All of this works fine on development. #mailer returns this:
#<Mail::Message:70180219750380, Multipart: false, Headers: <From: no-reply#example.com>, <To: fake#fake.com>, <Subject: Weekly Digest>, <Mime-Version: 1.0>, <Content-Type: text/html>>
When I run the exact same code on my AWS machine it returns:
#<Mail::Message:158221880, Multipart: false, Headers: <From: no-reply#example.com>, <To: fake#fake.com>, <Subject: Weekly Digest>, <Mime-Version: 1.0>, <Content-Type: text/plain>>
The content type on dev is html and its text/plain on prod.
Any ideas about why this might happen? Something in the environment settings? I'm not finding much helpful in the docs.
Could be a discrepancy in default_content_type between your environment configurations. Try adding:
config.action_mailer.default_content_type = 'text/html'
To either your production.rb config file, or optionally your application.rb config file.
You should also check if a text template exists at app/views/digest_mailer/weekly_digest.text.erb and remove it since you're only trying to send HTML emails anyway.
Longterm you should consider sending multipart emails with both text and HTML. The Premailer Gem makes it really easy by automatically generating the text-part from the HTML template. That way you don't have to maintain both a text and HTML template and keep them in sync.
I am working on a simple Rails app where I would like to play a video that is uploaded to the application. The video I am uploading is a h264/MP4 video, I have verified the codec. It's uploaded fine and I can watch the video in the browser if I go to the URL.
However, when trying to use HTML5 to display the video, on the page I get
Video format or MIME type is not supported
In my config/initializers/mime_types.rb file I have tried the following...
Mime::Type.register "video/mp4", :mp4
MIME::Types.add(MIME::Type.from_array("video/mp4", %(mp4)))
Taken from this question: Rails: MIME type issues with .m4v files
And I have also tried...
Rack::Mime::MIME_TYPES.merge!({
".ogg" => "application/ogg",
".ogx" => "application/ogg",
".ogv" => "video/ogg",
".oga" => "audio/ogg",
".mp4" => "video/mp4",
".m4v" => "video/mp4",
".mp3" => "audio/mpeg",
".m4a" => "audio/mpeg"
})
I remembered to restart my server after trying those different MIME initializers.
But neither seems to work. Any ideas?
EDIT: Also I should note when I run
curl -I http://localhost:3000/videos/SAMPLE.mp4 | grep Content-Type
I get back "Content-Type: video/mp4".
EDIT 2: Answer posted below.
Turns out everything I posted code-wise is fine. It was just a browser compatibility issue (MP4 on Firefox)...well, hopefully someone will find my misfortune useful!
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.