ruby : use credentials.yml.enc on heroku? - ruby

I'm new to the Ruby environment, and I wrote a ROR app that works fine locally.
I'm now trying to deploy it on Heroku, but it seems that it does not load my credentials.yml.enc, since the app crashes with a
undefined method `dig' for nil:NilClass (NoMethodError)
which is related to my line
Rails.application.credentials.odesli.dig(:api_key)
So it seems that Rails.application.credentials didn't load.
Any idea of how I have to handle this ?
Thanks.

it seems that I had to set the RAILS_MASTER_KEY var...
$ heroku config:set RAILS_MASTER_KEY=123456789

Related

undefined method `reset_all` for nil

F
An error occurred in an `around(:example)` hook
NoMethodError: undefined method `reset_all' for nil:NilClass
occurred at /usr/lib/ruby/vendor_ruby/rspec/mocks.rb:22:in `teardown'
I'm currently trying to run a ruby test suite, but running into issues when calling rspec spec/. I'm getting the above traceback. Any ideas as to what might cause this? I've tried updating rspec to no avail.
Any debugging tips are also appreciated.
Looks like it was simply a matter of an outdated ruby version!

Recurrent invalid byte sequence in UTF-8 with Rails

Environment
Rails 3.2.11
Ruby 1.9.1
utf8-cleaner gem
I am struggling with this issue for over a year now, and I am not able to reproduce it on my dev environment, which makes it rather difficult for me to understand why this is happening and how I can resolve. Here is the error notification I am getting (via email using ExceptionNotifier):
A ArgumentError occurred in home#index:
invalid byte sequence in UTF-8
.bundle/gems/ruby/1.9.1/gems/rack-1.4.5/lib/rack/utils.rb:104:in `normalize_params'
Apparently caused by Chinese spider:
HTTP_USER_AGENT : Mozilla/5.0 (compatible; EasouSpider; +http://www.easou.com/search/spider.html)
I have tried to a couple things, see my earlier question where I was attempting to catch the error.
I have also installer utf8-cleaner gem but that doesn't seem to resolve, unless I missed a step.
How can I reproduce the issue? Note the URL causing the problem is perfectly correct when I access it (?)
UPDATE 20140721 - use rack-utf8_sanitizer
Add gem 'rack-utf8_sanitizer' in Gemfile
Add config.middleware.insert 0, Rack::UTF8Sanitizer in application.rb
$ bundle install
That worked perfectly on DEV but FAILED on my Heroku PRODUCTION, with the following issue:
$ heroku run rake middleware --a test-app
Running `rake middleware` attached to terminal... up, run.4846
WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.7.6
rake aborted!
uninitialized constant Rack::UTF8Sanitizer
/app/config/application.rb:71:in `<class:Application>'
I am still investigating why I should be getting this.
I managed to fix it (on a Rails 3.2.18 app) as described in this gist:
https://gist.github.com/joost/ca4eda8f31655cf6095a
Reproduce the issue caused by
HTTP_USER_AGENT : Mozilla/5.0 (compatible; EasouSpider; +http://www.easou.com/search/spider.html)
Create a ruby script
#!ruby
invalid = "data\xed\xe5\xed\xe0".force_encoding('ASCII-8BIT')
`curl localhost:3000 -d #{invalid}`
Add the rack-utf8_sanitizer gem to your Gemfile
This resolved for my Dev environment, but wouldn't work on Heroku. I updated my question accordingly.
UPDATE:
I added require "rack/utf8_sanitizer" in my application.rb file and that seems to resolve, the Heroku issue.

Undefined method Zip::ZipOutputStream.write_buffer on Heroku

I'm making a basic Sinatra app to play around with the Passbook gem.
My app runs fine on localhost, but when I try and run it on Heroku I get this error message:
/app/vendor/bundle/ruby/2.0.0/gems/passbook-0.2.1/lib/passbook/pkpass.rb:122:in `outputZip'
/app/vendor/bundle/ruby/2.0.0/gems/passbook-0.2.1/lib/passbook/pkpass.rb:60:in `stream'
/app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.4/lib/sinatra/base.rb:1593:in `call'
NoMethodError - undefined method `write_buffer' for Zip::ZipOutputStream:Class:
This happens when I call the line passbook.stream.string in my app file.
I don't think Passbook is the problem here - it seems that the class method write_buffer exists in the version of Zip::ZipOutputStream on my local machine but isn't there on Heroku. Why is this? How can I get around it?
I've tried including both zip and rubyzip in my Gemfile, individually and at the same time, and neither of them solve the issue.
Whenever I see something like this, I always ask myself Do you have Dev/Prod parity?.
So:
What Ruby version do you use locally, and does it differ from what you're using on Heroku?
Do you specify a Ruby version in your Gemfile?
How do you run locally? Do you use bundle exec to ensure you run in the same way, with the same gems?
Finally figured it out.
When I ran ruby app.rb, things worked locally, but when I ran bundle exec ruby app.rb, I got the same error as I did on heroku.
I upgraded to the latest version of passbook (which was just updated today to handle the latest changes to rubyzip), but things still didn't work.
Turns out I needed to remove gem 'zip' from my Gemfile and just include gem 'rubyzip' - previously I had both.

Globalize2 problems, undefined method `translates' for?

I've set up Globalize2 on a rails app however I'm getting the following error when I put translates on the model:
undefined method `translates' for
Is anyone else getting this error? It's on rails 3 by the way.
You will have to use globalize3 if you run rails3.
You can download it from https://github.com/svenfuchs/globalize3 or by adding
gem "globalize3"
to you Gemfile and running bundle install.

NameError at / uninitialized constant Sass::SyntaxError

I am using Padrino and when I try to specify my application.sass file I get this error NameError at / uninitialized constant Sass::SyntaxError
I thought I might have something missing, so I checked out the sample_blog application at their GIT to verify my SASS is working correct. It was working correct and the blog app was running fine. Then I decided to change a line in the blog's application.sass and I got this error.
I am using TextMate to edit the file.
Weird indeed, any advices?
Yes, the issue is simple and already fixed in Padrino edge. Basically rename lib/sass.rb to lib/sass_plugin.rb. Check out the issue here: http://github.com/padrino/padrino-framework/issues/closed#issue/94

Resources