Rails 5: undefined method `megabytes' for 64:Integer when using in config/environment/staging.rb - ruby-on-rails-5.2

As explained in Caching with Rails Guide I added the following line to config/environment/staging.rb:
Rails.application.configure do
...
config.cache_store = :memory_store, { size: 64.megabytes }
...
end
This raised the error when starting Puma server:
undefined method `megabytes' for 64:Integer
Requiring the corresponding acctive_suport module on the top of staging.rb:
require 'active_support/core_ext/numeric/bytes'
...
solved the issue.
What am I missing ? Thank you.
Used Rails version: 5.2.2, API mode.
Ruby: 2.6.1.

Related

Undefined Method Formatter for Log4r in RAILS 4.0

I am getting this error after upgrading Rails from 3.1.2 to 4.0. When launching my server with rails s I got stuck with the following error
C:/ruby-2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/server.rb:78:in `start': undefined method `formatter' for #<Log4r::Logger:0x26dd908> (NoMethodError)
I have been on the Log4r site but haven't got any infor;ation about a bug when upgrading Rails.
Does anyone have any idea where this bug comes from. Thank you!
The method formatter is not defined on Log4r::Logger, but on Log4r::FileOutputter. Therefore I am surprised that is worked before the Rails update. Perhaps that changed between different versions of Log4r.
Please try the following (with adjusted filenames and patters):
require 'log4r'
outputter = Log4r::FileOutputter.new('log4r', filename: 'foobar.log')
outputter.formatter = Log4r::PatternFormatter.new(
date_pattern: "%FT%T.000Z", pattern: "%d [%l] %m"
)
logger = Log4r::Logger.new('log4r')
logger.outputters = [outputter]
Add this code to config/application.rb or to a new file like config/initializers/logger.rb

Ruby Sinatra NoMethodError

I've tried running this with Ruby 1.9.3 as well as 2.0, but nothing seemed to work. Here's the code:
require 'sinatra'
before do
set :display_string, 'Welcome from Ruby!'
end
get '/' do
settings.display_string
end
The error is:
NoMethodError at /
undefined method `set' for (sinatra application code here)
This code:
set :display_string, 'Welcome from Ruby!'
seems to cause the issue. I'm running Thin 1.5.1 , latest version of Sinatra 1.4.3
EDIT: It seems that this works well if set is not inside the "before do/end" block. So it's something about the set being in the before do/end block.
I think you should set your configure with configure block:
before do
configure do
set :display_string, 'Welcome from Ruby!'
end
end
see more sinatra docs about the configure

undefined method `configure' for Savon:Module

I'm getting the above error in a gem with this code snippet
Savon.configure do |config|
config.log = false
config.log_level = :error
HTTPI.log = false
end
This code used to pass in past runs on Travis, so I'm not sure why this changed when I altered the Readme.
Part of this confusion comes from my situation--inheriting a gem to maintain--along with this line in the gemspec:
gem.add_dependency 'savon'
There's no version number specified, so the newest run switched over to using Savon 2, which ditched the Savon.configure global behavior. If you're in the same boat as me, changing this line to the last pre-2.0 version of Savon will resolve the issue:
gem.add_dependency 'savon', '~>1.2.0'
Then bundle install and you should be good.
Or you want to upgrade your code. I know I do.
Savon.configure was removed from Savon 2.0 because the "problem was global state". The quickest way to keep the behavior the same in your app would be to define a app-level global hash in the same place. You'd then pass this hash into every Savon.client call you make. For instance:
# Where Savon.configure was called
APP_OPTS = {
# disable request logging, silences HTTPI as well
log: false,
# Don't log Laundry xmls to STDOUT
log_level: :error,
#... etc
}
# Elsewhere
#client = Savon::Client.new(APP_OPTS)
I'd consider this a starting point to migrating to the 2.0 configuration style. Ideally, you should always consider the client-specific 2.0 options available when initializing each Savon client.

Error with Rack fetching session-based cookie

My web app is using Rack 1.4.0, Sinatra v1.2.6, Thin v1.2.11, Ruby v1.9.2p180
Navigating to a page I get this error in the log:
TypeError - can't convert nil into String:
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/cookie.rb:152:in `hexdigest'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/cookie.rb:152:in `generate_hmac'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/cookie.rb:109:in `unpacked_cookie_data'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/cookie.rb:99:in `extract_session_id'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/abstract/id.rb:43:in `load_session_id!'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/abstract/id.rb:32:in `[]'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/abstract/id.rb:262:in `current_session_id'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/abstract/id.rb:268:in `session_exists?'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/abstract/id.rb:107:in `exists?'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/abstract/id.rb:122:in `load_for_read!'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.0/lib/rack/session/abstract/id.rb:59:in `[]'
/var/www/phrogz.net/routes/test.rb:8:in `logged_in?'
The code in test.rb line 8 is:
session[ :foo ] == "BAR"
Any suggestions on what to upgrade/downgrade to fix this?
Looks like you run into this issue. The fix is in Rack 1.4.1 so simply upgrading should fix it.

ruby-openid: #socket not set while performing discovery

I'm having a bit of truble with omniauth/openid.
When trying to authenticate, I found this in my logs:
OpenID::FetchingError: Error fetching https://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username: undefined method `io' for nil:NilClass
The important thing there is undefined method io' for nil:NilClass which comes from openid/fetchers.rb, in the following snippet:
module Net
class HTTP
def post_connection_check(hostname)
check_common_name = true
cert = #socket.io.peer_cert
cert.extensions.each { |ext|
next if ext.oid != "subjectAltName"
ext.value.split(/,\s+/).each{ |general_name|
if /\ADNS:(.*)/ =~ general_name
check_common_name = false
...
That error is generated by #socket.io.peer_cert, #socket is not defined.
Have any of you encountered this before? Not quite sure what the cause is.
Versions I'm running:
ruby 1.9.3dev (2010-08-17 trunk 29020) [x86_64-darwin10.4.0]
ruby-openid (2.1.8)
ruby-openid-apps-discovery (1.2.0)
omniauth 0.2.0
We had this same problem and it was a direct result of Net::HTTP#connect never being invoked. Turns out we had the fakeweb gem scoped into the environment that was throwing the error (development, in our case).
Narrowing fakeweb's scope allows for normal processing of #connect and #socket is once again happy.
group :test do
gem 'fakeweb'
end
We came across the same / very similar problem with both fakeweb and webmock (when using the VCR gem). Switching from fakeweb to typhoeus seemed to have solved this problem for us.

Resources