NameError (uninitialized constant Wizard) - ruby-on-rails

I thought everything in the App folder autoloads. Why would I be getting an (uninitialized constant) error?
app/form_models/user.rb
module Wizard
module User
end
end
I have been following these instructions.
https://medium.com/#nicolasblanco/developing-a-wizard-or-multi-steps-forms-in-rails-d2f3b7c692ce
However, keep getting error and the blog states:
" Remember that the Rails autoloading feature will load every Ruby class inside the app folder"

According to Rails auto-loader conventions this should be located in some path ending in wizard/user.rb but it's not.
One place to put it is app/models/concerns/wizard/user.rb where it can be loaded.

Related

Uninitialized constant WebHook::Endpoint when running zeitwerk test

I've recently started the upgrading process of my app to use Rails 6. Some of it is very smooth, some of it not.
The problem I am facing right now is that in a factory bot we define:
factory :webhook_endpoint, class: Webhook::Endpoint do
...
end
When running rails zeitwerk:check it simply throws Uninitialized constant WebHookEndpoint.
The module and class is defined in the models folder.
I wonder I need to require or include it for it to realize it exists.

Rails query object not loading

I have a query object in Rails 5.2.2
app/queries/car_query.rb
class CarQuery
attr_reader :relation
# code
end
when I reference it in the console, I get
Error
NameError (uninitialized constant CarQuery)
Since the folder/file is in the app directory, I thought it automatically gets loaded. Am I incorrect? If so, why would my form objects autoload and not these? How do I fix this?
Try running bin/spring stop in your console then restarting the app.
If that doesn't work add update you application.rb with
Spring.watch "app/queries/**"
Make sure that the name of the file corresponds to the class name, or else rails will have trouble loading it. That is to say, make sure the file name is car_query.rb, if CarQuery is the name of the class.
CarQuery.rb goes against rails naming conventions and will mess with autoloading.

Conflict between Rails Admin and Impressionist gems

I'm using the latest version of the Impressionist and Rails Admin gems, and wondering if anyone could shed some light on an annoying conflict I'm experiencing. The problem is roughly documented here - https://github.com/sferik/rails_admin/issues/1315, yet the vaguely described solution is not working for me. When I have the line is_impressionable in my Listing model, I get an error when starting my Rails server with rails s:
...rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined local variable or method `is_impressionable' for Listing(no database connection):Class (NameError)
If I first start the server, and then add the 'is_impressionable' line, everything works fine, so the problem only occurs during initialization. I don't fully understand the initialization process, so am not sure how to go about getting this to work.
I have tried moving all my rails_admin model configuration options to their respective models, rather than in the initializer, which had no effect. I also have the following line in my initializer:
config.included_models = [Listing,ListingImage,AllOtherModelsHere...]
I have tried adding single quotes around these model names, which results in the following errors, as described in the github issue here
[RailsAdmin] Could not load model Listing, assuming model is non existing. (undefined local variable or method `is_impressionable' for Listing(no database connection):Class)
Any ideas what else I can try to make these gems work together? I don't want to have to remove the is_impressionable line every time I want to restart the server or generate a migration...
Not sure if the same issue that I had but yet I will post what worked for me just in case someone struggles with this too:
Im on a ruby 2.1.5 project with rails 4.2.0 and among other gems I'm using rails admin.
I run into several weird problems trying to set this up. For instance if I added the is_impressionable call within one of my models for some reason the execution of that file stopped there and I started getting weird errors like any method declared below the is_impressionable failed with undefined error.
So what I end up doing was:
class MyModel < ActiveRecord::Base
include Impressionist::IsImpressionable
is_impressionable
end
So this solved my issue and now i can access #my_model_instance.impression_count as expected.
I changed every occurrence of Klass to 'Klass'.constantize in initializer.

Can't create users in rails when using authlogic because of cookies

So, I have a standard rails 3 app with authlogic. If I'm not in the browser (in the console or in the test environment), I can't create user models.
For example:
I have this code either in a rspec test or in my console:
user = User.create(...user attributes...)
And I get this error:
NoMethodError: undefined method `cookies' for main:Object
I've looked all over the internet and can't figure this out. Any help would be greatly appreciated.
EDIT:
So, I looked around some more and found in the documentation to do this:
include Authlogic::TestCase
but then I get this error:
uninitialized constant Authlogic::TestCase
I had this same exact problem. Where in your application did you put the following line:
Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)
I ran into this error when I placed the line in either the environment.rb file or within a file within my initializer folder.
I eliminated the problem when I placed the line in my ApplicationController instead.

Uninitialized constant error in Rails with new test

Why am I getting this error?
https://gist.github.com/770219
Your LegalDocument model may be defined in a filename that is not correct. The file must be located in any subdirectory of app and be called legal_document.rb. The name is really important, as this is how Rails does autoloading.

Resources