How to create a custom formatter for Faraday logging? - ruby-on-rails

In the Gemfile, the gem is listed like this:
gem "faraday"
This leads to the installation of the current version 1.10.0.
Then, following this documentation, I create a custom logger, but I get an error:
NameError: uninitialized constant Faraday::Logging
Did you mean? Logger
If open the Rails console and write the code Faraday::Logging::Formatter there, the error will be exactly the same.
Tell me, please, what is the matter and how to fix it?
UPD.
If I write this in the Rails console:
Faraday::Response::Logger::Formatter
Then I get this error:
NameError: uninitialized constant Faraday::Response::Logger::Formatter
Then I write this:
Faraday::Logging::Formatter
And there are no more errors. What is going on?
bundle exec rails c
Faraday::Logging::Formatter
=> NameError: uninitialized constant Faraday::Logging
Faraday::Logging::Formatter
=> NameError: uninitialized constant Faraday::Logging
Faraday::Response::Logger::Formatter
=> NameError: uninitialized constant Faraday::Response::Logger::Formatter
Faraday::Logging::Formatter
=> Faraday::Logging::Formatter

Related

After adding the gem "webmock" I have "uninitialized constant Syck (NameError)"

I've added gem "webmock" and started having an error:
$ rspec
/home/me/.gem/ruby/2.3.1/gems/safe_yaml-1.0.1/lib/safe_yaml/syck_node_monkeypatch.rb:42:in `<top (required)>': uninitialized constant Syck (NameError)
I've tried includig this:
module SafeYAML
YAML_ENGINE = defined?(YAML::ENGINE) ? YAML::ENGINE.yamler : (defined?(Psych) && YAML == Psych ? "psych" : "syck")
end
into different initialization files such as application.rb and initializers/my_init.rb, but it didn't help to fix the error. How can I fix it?

Why is irb returning NameError: uninitialized constant for all objects in the database?

I am half way through building a Q&A app and I have successfully seeded my database and can see that objects have been created both in my browser and in the server logs and previously in irb. Now when I went to try to inspect an object in irb, for every object I give it, irb returns "NameError: uninitialized constant". For example:
2.0.0-p481 :001 > user = User.find(1)
NameError: uninitialized constant User
from (irb):1
from /home/vagrant/.rvm/rubies/ruby-2.0.0-p481/bin/irb:12:in `<main>'
2.0.0-p481 :002 > question = Question.find(1)
NameError: uninitialized constant Question
from (irb):2
from /home/vagrant/.rvm/rubies/ruby-2.0.0-p481/bin/irb:12:in `<main>'
2.0.0-p481 :003 > user = User.find
NameError: uninitialized constant User
from (irb):3
from /home/vagrant/.rvm/rubies/ruby-2.0.0-p481/bin/irb:12:in `<main>'
2.0.0-p481 :004 > user = User.new
NameError: uninitialized constant User
from (irb):4
from /home/vagrant/.rvm/rubies/ruby-2.0.0-p481/bin/irb:12:in `<main>'
I'm new to programming, so if anyone could explain why this might be happening it would be much appreciated!
It looks like you're running irb when you want rails console (or rails c for short).
Because you need to use rails console, not irb.
rails console
(I assume you are building a Rails application)

Httparty in rails

I am trying to learn how to use httparty. I ran 'gem install httparty', first in my terminal, expecting to be able to use it in a pry session but no luck.
Next, I created a new rails app, added the gem to my gem file and ran bundle and in a pry session tried to use httparty as follows:
[1] pry(main)> HTTParty.get("http://rubygems.org/api/v1/versions/httparty.json")
NameError: uninitialized constant HTTParty
from (pry):1:in `__pry__'
[2] pry(main)> HTTParty.get("http://rubygems.org/api/v1/versions/httparty.json)
[2] pry(main)* httParty.get("http://rubygems.org/api/v1/versions/httparty.json)
SyntaxError: unexpected tIDENTIFIER, expecting ')'
httParty.get("http://rubygems.org/api/v1/versions/httparty.json)
^
[2] pry(main)> httParty.get("http://rubygems.org/api/v1/versions/httparty.json")
NameError: undefined local variable or method `httParty' for main:Object
from (pry):2:in `__pry__'
[3] pry(main)> response = httParty.get("http://rubygems.org/api/v1/versions/httparty.json")
NameError: undefined local variable or method `httParty' for main:Object
from (pry):3:in `__pry__'
[4] pry(main)> response = HTTParty.get('https://api.stackexchange.com/2.2/questions?site=stackoverflow')
NameError: uninitialized constant HTTParty
from (pry):4:in `__pry__'
Any help would be much appreciated. Thank you
require the gem, either in your pry invocation
pry -rhttparty
or once in pry
require 'httparty'
I am working on the exact same thing right now. What I did was create a file test_party.rb in the rails lib directory. (Make sure to add config.autoload_paths += %W(#{config.root}/lib) to your config/application.rb
In the new lib file create a class TestParty and include HTTParty
Then in rails console you can run TestParty.whatever_you_want
Hope that helps!

What does uninitialized constant mean?

I'm getting the error uninitialized constant SessionsController I've searched, and can only find explanations of this error in reference to a NameError Does anyone know what the error means?
That is one of two "subtypes of" Name Error dealing with uninitialized variables. The language of "uninitialized constant" is due to the fact that SessionsController is capitalized. Both types are illustrated below:
new-host-3:bot palfvin$ irb
2.0.0p247 :001 > foobar
NameError: undefined local variable or method `foobar' for main:Object
from (irb):1
from /Users/palfvin/.rvm/rubies/ruby-2.0.0-p247/bin/irb:16:in `<main>'
2.0.0p247 :002 > Foobar
NameError: uninitialized constant Foobar
from (irb):2
from /Users/palfvin/.rvm/rubies/ruby-2.0.0-p247/bin/irb:16:in `<main>'
2.0.0p247 :003 >
It means that you're trying to use a Class or a Module that wasn't defined yet. Probably because you forgot to require them.
Make sure that this class SessionsController has been declared in your sessions_controller.rb.
Read more: http://ruby.about.com/od/faqs/qt/Nameerror-Uninitialized-Constant-Object-Something.htm

The gem I compiled broke my app, makes it so all the models are uninitialized contants

The deep_cloning gem is causing this error:
NameError: uninitialized constant %{AnyModel}
When I do bundle update, it tells me this:
deep_cloning at /Users/me! =D/.rvm/gems/ruby-1.8.7-p352#secret_gemset/bundler/gems/deep_cloning-423f1e30eeef did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
The validation message from Rubygems was:
["deep_cloning-0.2.0.gem"] are not files
What am I doing wrong here?
In my Gemfile I specify the path to the gem like so:
gem "deep_cloning", :git => "git://github.com/DerNalia/deep_cloning.git"
Update: the stacktrace from the unitialized constant error:
> MyModel.find(455)
NameError: uninitialized constant MyModel
from /rvm_gemset_path/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:443:in `load_missing_constant'
from /rvm_gemset_path/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `rake_original_const_missing'
from /rvm_gemset_path/gems/rake-0.8.7/lib/rake.rb:2503:in `const_missing'
from /rvm_gemset_path/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:92:in `const_missing'
from (irb):1
You should remove the line :
s.files = [
...
"deep_cloning-0.2.0.gem"
...
]
from your gemspec.

Resources