Can I use Rails gem from another gem? - ruby-on-rails

I am developing a simple gem. as part of it, I want data-caching to which I need rails gem. I included the required statements in gemspec. But still, it is not loading Rails. I am getting below error
NameError:
uninitialized constant FormattingHelper::Rails

Instead of using Rails for caching, I used below class and fixed the problem
ActiveSupport::Cache

Related

block in load_missing_constant': uninitialized constant API::V1::Users (NameError)

Im trying to set up api endpoints for my rails application and keep receiving this error my environment is Ruby 2.6 and Rails 5.2 and im using the 'grape' gem for the api here is the blog I followed to set it up. https://medium.com/#ryanwaldorf/how-to-add-an-api-to-an-existing-rails-app-1d2419ba91bd
here is a link to my repo https://github.com/jslack2537/apiDemoApp
I believe the issue is wither in my config/routes.rb or my application.rb files.
But I could be totally wrong. This is a challenge app and not going to be used in production.
This mainly occurs when naming conventions doesn't match. Try changing api/v1/user.rb to api/v1/users.rb which also the blog suggests. You missed a 's'.

uninitialized constant Users::RegistrationsController::Shortener Devise + Gem

I'm using a gem called Shortener: https://github.com/jpmcgrath/shortener
Its goal is to shorten some urls of my website such as www.mywebsite.com/users/sign_up?&invitcode="test" would become www.mywebsite.com/shorturl.
I meet a problem in my Devise registration_controller.rb where I'm trying to use this gem. When I called it with Shortener::ShortenedUrl.generate("www.example.com") I get a uninitialized constant Users::RegistrationsController::Shortener.
If I do the same command in my console, it's working perfectly. I guess it's because Rails cannot find Shortener in my devise module? Can you tell me how I should solve this?

Need to initialize a constant before gem initialization ( rails 3 and rails 4)

I am implementing a omniAuth authentication system through a gem and i would need to initialize a constant before the gem gets loaded.
Scenario:
The developer should write that constant in a config file, restart its server and that constant should be initialized before the gem gets loaded.
I tried to put it in a config/initializers/omniauth.rb file but i get a error when loading the server
unitialized constant OmniAuth::Strategies::Xyz::URL.
i am writting it in the gem in this manner:
OmniAuth::Strategies::Xyz::URL= "http://my_account.com"
If you want to set a constant before gems are loaded in a Rails app, you can place it in config/application.rb, just before the Bundler.require statement. However, since no gems have been loaded yet, you might run into trouble setting such a deeply nested constant.
The proper way to do this, is not to rely on constants for configuration. Make a proper configuration object. You can make a Railtie to add a proper configuration option to Rails itself and define the right hooks like to_prepare to start loading your gem's configuration at the right time.

Rails 3.2: Undefined method 'class_inheritable_accessor' in activemerchant

I'm building my first Rails app and trying to integrate active_paypal_adaptive_payment with Rails 3.2.1, however when I try to boot up the rails server it runs into the problem of, "undefined method 'class_inheritable_accessor' (in line 4 of post_date.rb) in the activemerchant-1.5.1 gem of which is a dependency.
I've looked around and seems this method has been removed in rails 3.2. From what I understand, it's not as simple as going into the activemerchant gem and replacing class_inheritable_accessor with class_attribute (read this conversation).
Any ideas on how I could update this gem so it could be compatible with Rails 3.2? It's an outstanding issue on the github page so appreciate any help with it!
This particular commit solved my issue: https://github.com/cmezak/active_paypal_adaptive_payment/commit/c6661704c45b73a0be5c608c673b106ac1eb5b69

I'm Getting An Uninitialized Constant Error From A Recently Installed Gem. How do you fix this?

I recently installed the Citier Gem. Its Gem a solution for simple Multiple Class Inheritance in Rails. After setting up models per the instructions and running Rake, I am getting the following error:
uninitialized constant Books::Writable
*/citier/core.ext.rb:33:in 'create_citier_view'
Its been my experience that this error message usually means the Gem is not installed properly, but I've checked my Gemfile and did a Bundler Show command and everything seems to be in order. Apparently, the core.ext file referenced in the error is supposed to be extending ActiveRecord to create views that are utilized for Multiple Class Inheritance.
I checked all the usual places for the problem but can't seem to figure this out. In suggestions or ideas would be greatly appreciated. I've been stuck on this one for a couple of days now.
Thanks for you input.
Simply type require 'rails_sql_views' in config/application.rb
U may need install gem rails_sql_views

Resources