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
Related
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
In config/environments/production.rb (and the other environments) there is:
config.eager_load = true
and a whole bunch of other config.foobar calls. But where does 'config' come from? Usually you have something like:
SomeClass.each do | block_variable |
block_variable.some_method
end
but in the case of the mystical 'config' this is not the case, its like a block variable which is not declared anywhere. Opening rails console, when I do:
irb(main):001:0> config
NameError: undefined local variable or method `config' for main:Object
Did you mean? conf
from (irb):1
irb(main):002:0>
and the same result occurs for app.config
irb(main):002:0> app.config
NoMethodError: undefined method `config' for #<ActionDispatch::Integration::Session:0x00007fc898d02808>
from (irb):2
How is it possible for ruby to allow calls on 'config'?
These classes include the ActiveSupport::Configurable module:
https://api.rubyonrails.org/classes/ActiveSupport/Configurable.html
Here is an alternative to implementing this behavior by yourself:
https://robots.thoughtbot.com/mygem-configure-block
I'm having this weird error with Rails 5 action mailer.
# app/mailers/application_mailer.rb
class ApplicationMailer < ActionMailer::Base
default from: "from#example.com"
layout 'mailer'
end
irb
~/workspace/rails5 > rails c ruby-2.4.1#rails5
Running via Spring preloader in process 45498
Loading development environment (Rails 5.1.2)
2.4.1 :001 > ApplicationMailer
NameError: uninitialized constant Mail::TestMailer
from app/mailers/application_mailer.rb:1:in `<top (required)>'
from (irb):1
2.4.1 :002 > ApplicationMailer
NoMethodError: undefined method `default' for ApplicationMailer:Class
from app/mailers/application_mailer.rb:3:in `<class:ApplicationMailer>'
from app/mailers/application_mailer.rb:1:in `<top (required)>'
from (irb):2
2.4.1 :003 >
This is the default Scaffold of rails 5.
Two really weird things happen the first is that it always tells me the uninitialized constant then trows default is not a method right after.
Just wondering how to fix it or if I should downgrade to Rail 5.0
The solution turned out to be that if you have a model named mail the ActionMailer will grab that one first instead of the rails class. If this happens then it fails the first time but the second time will load the rails class and try and smash them together. Allowing the submodule to work but treating the main class as a monkey path.
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)
I try to create User instance of my user model in irb. but it gives me this error
1.9.3p194 :001 > u = User.new
NameError: uninitialized constant User
from (irb):1
from /home/darshana/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'
any help?
irb doesn't loads rails for you.
try bundle exec rails console