Net::IMAP uninitialized constant error - ruby-on-rails

I really don't know where to start with this one, but I am (first time) using Net::IMAP and I am getting the following error:
NameError in EmailsController#connect
uninitialized constant Net::IMAP
Extracted source (around line #4):
2
3 def connect
4 imap = Net::IMAP.new('outlook.office365.com')
5 imap.authenticate('LOGIN', '**#**.com', '**')
6 imap.examine('INBOX')
7 #emails = imap.search(["RECENT"])
Not really sure what is going on here, I don't have to have anything in my Gemfile.rb? Or anything else before I set the imap variable?

You need to require 'net/imap' at the top of the file to bring Net::IMAP into scope.

Related

Rails 5.2, Erratic "Unable to autoload constant": sometimes it works, sometimes not

I have a view that ajax-loads the same partial a number of times. Each one contains the result of a rather extensive calculation which takes a number of seconds. On my machine, about 3 times out of 20, instead of the partial I get the error message "Unable to autoload constant Answers::Node::Questions::KurzSinglePunch... expected .../app/models/answers/node/questions/kurz_single_punch.rb to define it" (I shortened the text and the path for legibility). The file is obviously there, since in 17 of 20 cases it is found, and the partial displays correctly in these cases.
In case this is relevant, I use Puma in single mode on a six-year-old Mac running OS 11.6.
This is the topmost part of the error message:
LoadError in KurzReportsController#company Unable to autoload constant Answers::Node::Questions::KurzSinglePunch,
expected /Users/marion/Documents/Projekte/myproject/app/models/answers/node/questions/kurz_single_punch.rb to define it
Extracted source (around line #511):
#509 else
#510 require_or_load(expanded, qualified_name)
*511 raise LoadError,
"Unable to autoload constant #{qualified_name}, expected #{file_path} to define it" unless from_mod.const_defined?(const_name, false)
#512 return from_mod.const_get(const_name)
#513 end
#514 elsif mod = autoload_module!(from_mod, const_name, qualified_name, path_suffix)
Extracted source (around line #195):
#193 def const_missing(const_name)
#194 from_mod = anonymous? ? guess_for_anonymous(const_name) : self
*195 Dependencies.load_missing_constant(from_mod, const_name)
#196 end
#197
#198 #
We assume that the name of the module reflects the nesting
Extracted source (around line #285):
#283 constant.const_get(name)
#284 else
*285 candidate = constant.const_get(name)
#286 next candidate if constant.const_defined?(name, false)
#287 next candidate unless Object.const_defined?(name)
#288 Rails.root: /Users/marion/Documents/Projekte/myproject
Application Trace app/exporters/kurz_report_extractor.rb:63:
in `infos_for_question_id' app/exporters/kurz_report_extractor.rb:59:
in `block in build_survey_hash' app/exporters/kurz_report_extractor.rb:59:
in `map' app/exporters/kurz_report_extractor.rb:59:
in `build_survey_hash' app/exporters/kurz_report_extractor.rb:15:
in `initialize' app/controllers/kurz_reports_controller.rb:27:
in `new' app/controllers/kurz_reports_controller.rb:27:
in `block in company' app/controllers/kurz_reports_controller.rb:25:
in `each' app/controllers/kurz_reports_controller.rb:25:in `company'
After that there is a long section with a Framework trace.
How can it be that Rails is sometimes unable to find this file? And how can I fix this?

I am getting error when using hook in Rails application

Can some explain what these two line is used for in the application.html.haml file. I am using Rails 6
= hook(:stylesheet_includes, self) do
#{yield :stylesheet_includes}
I am getting the following error
undefined method `hook' for #<#<Class:0x000000000bb090b8>:0x0000000007886f10>

undefined method `+' for nil:NilClass in sample saml application

Trying to follow the setup here to create a simple SAML application (full project I got here).
I went through and did the setup
bundle install
rails s
This went fine, but when I navigate to
http://localhost:3000/
I get hit with
NoMethodError in SamlController#init
undefined method `+' for nil:NilClass
Extracted source (around line #9):
def init
request = OneLogin::RubySaml::Authrequest.new
direct_to(request.create(saml_settings))
end
def consume
I added some logging to check nil status of request and saml_settings but that seems to return false for both of them
puts request.nil?
puts saml_settings.nil?
Error trace:
Processing by SamlController#init as HTML
false
false
Created AuthnRequest: <samlp:AuthnRequest AssertionConsumerServiceURL='http://localhost:3000/saml/consume' ID='_394fa0a0-f313-0135-85a4-6a0001e18280' IssueInstant='2018-02-13T17:42:45Z' Version='2.0' xmlns:saml='urn:oasis:names:tc:SAML:2.0:assertion' xmlns:samlp='urn:oasis:names:tc:SAML:2.0:protocol'><saml:Issuer>http://localhost:3000/saml/consume</saml:Issuer></samlp:AuthnRequest>
Completed 500 Internal Server Error in 15ms (ActiveRecord: 0.0ms)
NoMethodError (undefined method `+' for nil:NilClass):
app/controllers/saml_controller.rb:9:in `init'
(Note: the error is line 5, it says line 9 for me because of debug logging I added)
I'm not too sure what else it could be, not sure what method it can't find and what is nil?
I have never messed with ruby stuff, but from my initial looks I'm not sure where the nil is coming from, the logs show the request being created so not sure. Any help would be appreciated, thanks!
Firstly I think you're using a pretty old ruby-saml gem version. That might be the problem.
I haven't tested your code, but it seems to me that you forgot to set idp_sso_target_url in your settings, and apparently that's the only place it can throw the exception you got. https://github.com/onelogin/ruby-saml/blob/v1.1.2/lib/onelogin/ruby-saml/authrequest.rb#L39
Posting the answer here, turns out that i was using a metadata url for the OKTA_METADATA environment variable.
Had to modify
settings = idp_metadata_parser.parse(ENV['OKTA_METADATA'])
to
settings = idp_metadata_parser.parse_remote(ENV['OKTA_METADATA'])
where
OKTA_METADATA=http://blahblahblah.com/metadata

Rails 5: Error when removed quiet_assets_path from development.rb

I have been trying to upgrade my app from Rails 4 to Rails 5. In my Rails 4 version I have quiet_assets_path set but in Rails 5 it is not required. But when I removed that tried to start the server I am getting the following error,
> ruby-2.2.2/gems/rack-mini-profiler-0.10.2/lib/mini_profiler_rails/railtie.rb:93:in
> `>': comparison of Fixnum with nil failed (ArgumentError) from
> /Users/Admin/.rvm/gems/ruby-2.2.2/gems/rack-mini-profiler-0.10.2/lib/mini_profiler_rails/railtie.rb:93:in
> `block in <class:Railtie>'
Can someone help me with this?
Edit:
Following is my rack_profiler.rb,
if Rails.env.development? || Rails.env.production?
require 'rack-mini-profiler'
# initialization is skipped so trigger it
Rack::MiniProfilerRails.initialize!(Rails.application)
Rack::MiniProfiler.config.skip_schema_queries = true
Rack::MiniProfiler.config.skip_paths += %w(/admin/sidekiq)
Rails.application.middleware.delete(Rack::MiniProfiler)
Rails.application.middleware.insert_after(Rack::Deflater, Rack::MiniProfiler)
end
When I comment the delete line then server is starting but if the line uncommented then the server breaks.
thanks for the update. First of all, do you use Rack::Deflater middleware in development environment too?
I think this issue might help you. It basically says that in Rails all delete middleware operations are issued at the end. You can use the swap method as described in the above issue.
If you search the repo issues for "Deflater" you'll find a lot of results, but I believe the above contains your fix.

RSRuby installation and R configuration error

I tried to install RSRuby following the steps mentioned in http://web.kuicr.kyoto-u.ac.jp/~alexg/rsruby/manual.pdf and http://nsaunders.wordpress.com/2009/05/20/baby-steps-with-rsruby-in-rails/ and I must say that nsaunders blog is indeed a great start for anyone installing RSRuby. But when I tried to check from the irb by creating an instance of RSRuby:
r = RSRuby.instance
it returned me error:
1.8.7-p371 :001 > r = RSRuby.instance
NameError: uninitialized constant RSRuby
from (irb):1
I have all the prerequisites: R_HOME, shared lib option and other stuff. I dont know why I got this error. Any ideas guyzz?????
has anyone tried it for rails successfully???
Without seeing the full source code it's difficult to give you an answer, so this is just a guess. Did you remember to require 'rsruby' within your code? NameError is often caused when a gem is installed but the code does not include the appropriate require statement:
require 'rsruby'
r = RSRuby.instance
You can see this in the code example in the "Documentation" section of the README in the GitHub project.

Resources