How to require ActiveRecord In IRB
Try require('active_record')
If you take a look at the gem Github repo the actual file name is active_record.rb so the above code should work.
https://github.com/rails/rails/tree/master/activerecord/lib
Requiring ActiveRecord on IRB - Ruby (NO Rails)
Two things to change here:
- Always put quotes around the path you're requiring. The reason Ruby is saying "undefined local variable or method" is that it's trying to interpret
config
as a variable name. Put the name in quotes and it won't. - Use
require_relative
when loading files that are part of your application.require
only looks in the default Ruby load paths.
Try this:
require_relative 'config/application.rb'
Do I need a model to insert through IRB?
yes error is due to not having a Department class or model. You can just create a department.rb and inherited from active record in your app/models directory with your favourite editor. for example with vim you can do
vim app/models/department.rb
edit the above file to have following
class Department < ActiveRecord::Base
end
and then reload the irb session with reload!
What all things can you access when you require a gem?
Thats up to the gem developer. To see how your Name- and Objectspace changed there should be many clever ways.
I answer shortly how to find out which new Module (-Constants) there are:
initial_modules = Module.constants
# -> [:Object, :Module, :Class, :BasicObject, :Kernel, :NilClass, ...]
require 'rails'
Module.constants - initial_modules # all NEW constants
# -> [:Pathname, :OpenSSL, :Digest, :SecureRandom, :Concurrent, :I18n, :CGI, :ActiveSupport, :Set, :SortedSet, :Timeout, :TimeoutError, :Logger, :LoggerSilence, :DateAndTime, :Psych, :StringScanner, :ScanError, :Date, :DateTime, :YAML, :Base64, :TSort, :Rails, :BigDecimal, :BigMath, :TZInfo, :ThreadSafe, :Threadsafe, :SynchronizedDelegator, :JSON, :OpenStruct, :Singleton, :Mutex_m, :ActionPack, :Rack, :ActionDispatch, :Mime]
As you see, this also comes with a lot of new stuff that is required (but not provided) by Rails, like Date, OpenSSL, etc.pp.
Actually, requirements can happen at runtime, too, such that this lists grows as you use the code.
Hope that helps a bit.
forcing an unmaintained ActiveRecord adapter to Rails version 6
@rmlockerd and @ruby_object were both correct in helping to debug, but at the end of the day I'd just written the section of code in a way that didn't work.
debugging was key
While doing a practice db migration in rails using irb, receiving error message NameError:uninitialized constant ActiveRecord
You need to require 'active_record'
. I agree that you may run into other issues trying to migrate by hand.
uninitialized constant ActiveRecord
start your irb
session with
rails console
and not:
irb
rails console
would load your rails
environment and your model for you, so you can do things like:
User.all
or User.new
without loading the class
as it has been preloaded by rails console
already
How to write tests for ActiveRecord extension gem
You probably want to have a look at acts_as_fu gem: https://github.com/nakajima/acts_as_fu.
Btw, you can use db in your rspec tests, but you don;t want to do this to test extensions.
Related Topics
Illegal Quoting in Line 1 Using Ruby CSV
How to Marshal a Hash with Arrays
Setting a Text Field That Has a Jquery Mask on It
Ruby: How to Dynamically Replace Parameters in Native Pg Gem
How to List All Databases with Activerecord
Pass Ruby Script File to Rails Console
Utc Time Resets to 2000-01-01 (Ruby). How to Prevent the Time from Resetting
Why Use Gems for Serving Assets Instead of the Vendor File
What Ruby Features Are Used in Chef Recipes
How to Render the Ajax Response in Rails
Define a Class Method in a Module
How to Access Ruby Method Inside Module and Inside a Class from Another .Rb File