Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4027270
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:04:33+00:00 2026-05-20T11:04:33+00:00

Can you create and initialize an ActiveRecord object like this? exercise = Exercise.new exercise.name

  • 0

Can you create and initialize an ActiveRecord object like this?

exercise = Exercise.new
exercise.name = "foo"
exercise.description = "bar"
exercise.unit_id = 123

I am trying to do this and I keep getting

ActiveRecord::ConnectionNotEstablished - ActiveRecord::ConnectionNotEstablished:
 /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:326:in `retrieve_connection'
 /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_specification.rb:123:in `retrieve_connection'
 /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_specification.rb:115:in `connection'
 /usr/lib/ruby/1.8/active_record/base.rb:1271:in `columns'
 /usr/lib/ruby/1.8/active_record/base.rb:3014:in `attributes_from_column_definition_without_lock'
 /usr/lib/ruby/1.8/active_record/locking/optimistic.rb:55:in `attributes_from_column_definition'
 /usr/lib/ruby/1.8/active_record/base.rb:2434:in `initialize'
 main.rb:14:in `new'

I just want to create and initialize the object then call a .save method. If I am going about this incorrectly, please let me know.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:04:34+00:00Added an answer on May 20, 2026 at 11:04 am

    Short Answer: Yes, you need a connection!

    You cannot (generally) use ActiveRecord unless there is a connection.

    The set of attributes on the object is determined by the columns on the table. Which means you can’t use the object unless you have the connection.

    In any case what would happen after calling exercise.save if there is no connection?

    So if you only need the validation, you can reuse ActiveSupport::Validation on a transient class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can initialize or create a new CCSprite object using the following code: NSString
In Postgresql you can create additional Aggregate Functions with CREATE AGGREGATE name(...); But this
this question can create a misunderstanding: I know I have to use CSS to
Is there anyway I can create a not in clause like I would have
I'm trying to generate NHibernate mappings with ActiveRecord. I can create classes from a
I create a new object of type Spam, with attr_accessor to both hooray and
Is it possible to create an attribute that can be initialized with a variable
I can create a menu item in the Windows Explorer context menu by adding
I can create the following and reference it using area[0].states[0] area[0].cities[0] var area =
I can create a literal long by appending an L to the value; why

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.