ruby gem issue uninitialized constant - ruby-on-rails

Ok I'm not a pro at creating gems, but I tried my best and created this gem https://rubygems.org/gems/webpack_native/versions/0.2.0
This gem has generators and if I use it from the local folder (meaning the gem folder is in my computer) it works fine, if I type rails g in terminal it shows me the generators including my gem's generators
But using it from rubygems always give me an error uninitialized constant WebpackNative:
/home/mody/.rvm/gems/ruby-2.7.0#myapp/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/active_support.rb:80:in `block in load_missing_constant': uninitialized constant WebpackNative (NameError)
any thoughts on this?

I'm not sure how this happen but I get it to work after I installed devise gem and run
rails g
the output of the available generators shows up including my gem, and the generator itself is working.

Related

How to add dependencies to Rails engine's dummy app?

I would like to add a few dependencies in my test/dummy app so that I can do integration test of my engine. I added a test/dummy/Gemfile and put the dependencies on it:
gem 'devise'
gem 'devise_invitable'
after I run bundle install inside the test/dummy, the test/dummy/Gemfile.lock is created.
but when I run rails g devise:install inside the test/dummy, it says
method_missing': undefined method `active_storage' for #<Rails::Application::Configuration:0x00007fad8f2a0dc0> (NoMethodError)
How am I able to add dependencies to the dummy app?
The only way I can get it to work is if I add it to the dependencies of my engine gem. but I prefer not to do that
EDIT: I added rails in my Gemfile and devise install can be run, but after I run my test, it has this error:
test/dummy/config/initializers/devise.rb:11:in `<top (required)>': uninitialized constant Devise (NameError)

What's the replacement for acts_as_commentable in Rails 6, Ruby 3.0.2?

I upgraded our app to Rails 6.1.4.4 and Ruby 3.0.2. I have this old gem
gem 'acts_as_commentable'
Locked at version 4.0.2. The gem does not appear to be supported anymore, which is a shame because when I start up my app or console, I now get this error
$ rails c
Your Gemfile lists the gem rspec-rails (>= 0) more than once.
You should probably keep only one of them.
Remove any duplicate entries and specify the gem only once.
While it's not a problem now, it could cause errors if you change the version of one of them later.
/Users/myuser/.rvm/gems/ruby-3.0.2/gems/hash_dot-2.5.0/lib/hash.rb:19:in `method_missing': undefined method `arity' for {:as=>:commentable, :dependent=>:destroy}:Hash (NoMethodError)
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:53:in `build_scope'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:47:in `create_reflection'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:32:in `build'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations.rb:1458:in `has_many'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/acts_as_commentable-4.0.2/lib/commentable_methods.rb:58:in `acts_as_commentable'
…
Is there any simple replacement for this gem or way to monkey-patch this error so I can start up the app?
Looking over the forks, I found this one that appears to work for me using Rails 6.0.6 and Ruby 3.0.5.
https://github.com/alazycoder101/acts_as_commentable.git
I have not tested it extensively yet, but at least the basic functionality seems to be working for me. Hope this helps.
For clarity, to use that fork you would use the following line in your Gemfile:
gem 'acts_as_commentable', git: 'https://github.com/alazycoder101/acts_as_commentable.git'

rails6 app: minitest failing with ActionView::Template::Error: uninitialized constant

A bit of a puzzler - I've got an app using a very simple gem I wrote (UIAvatars) to generate a URL to an Avatar API. This demonstrably working in my Development rails app (the Avatar is displayed with no issues) but when I try to run my controller tests it causes errors like so:
Error:
InitiativesControllerTest#test_should_get_new:
ActionView::Template::Error: uninitialized constant ProfilesHelper::UIAvatars
app/helpers/profiles_helper.rb:17:in `profile_image_link_for'
app/views/layouts/_header.html.erb:62
app/views/layouts/application.html.erb:23
test/controllers/initiatives_controller_test.rb:15:in \`block in <class:InitiativesControllerTest>'
The method in profiles_helper is:
def profile_image_link_for(profile, **options)
image_tag(
UIAvatars.generateURL(name: profile.full_name, size: "128", background: "random"),
options
).html_safe
end
bundle says it is installed:
% bundle info ui_avatars
* ui_avatars (0.0.1)
Summary: Generate avatars with initials from names using https://ui-avatars.com
Homepage: https://rubygems.org/gems/ui_avatars
Path: /Users/thatsme/.rvm/gems/ruby-2.6.6/gems/ui_avatars-0.0.1
it's in my Gemfile in the default group
gem 'ui_avatars'
Any idea what could be causing this problem?
Answer is that .ruby-version had a different version of ruby (2.6.7) than I was actually using (2.6.6) and so ruby could not find the gem installed in the expected path when running minitest.
(why it still worked in rails is a question for another day).

Deep Clone gem for rails 2.3.8?

I found this http://rubygems.org/gems/deep_cloneable
but it has only been tested with rails 3.
I tried it out, but all of my active record models became undefined. lol.
specifically: load_missing_constant': uninitialized constant ActiveRecord (NameError)
So, I was wondering if there is any sort of active record deep clone gem for rails 2?
i know this is not very kind, but: RTFM
Installation
Install by adding the gem to your Gemfile
gem ‘deep_cloneable’
Rails 2:
gem install deep_cloneable, ‘~> 1.2.4’

Devise issue Ruby on rails

I'm trying to get Devise working. I'm following this tutorial which tells me to do "rails generate devise User" but when I do that command, it gives me an error saying
"NameError: uninitialized constant User from /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2503:in `const_missing'"
What am I doing wrong? I'm using Rails 3.0.9, Ruby 1.8.7 and Ubuntu 11.04
Thanks a bunch in advance,
Michael.
Do you have gem devise in your Gemfile? Then, run bundle install. You can also try putting require 'devise' in your config/application.rb file (but you shouldn't have to do this).

Resources