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 7751945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:40:42+00:00 2026-06-01T11:40:42+00:00

—–UPDATE—– Well, seems that the problem was in last.id . When database is created

  • 0

—–UPDATE—–

Well, seems that the problem was in last.id. When database is created works OK, but when not fails. Now the question is different: How can I create a field using the id from the same row?

——–ORIGINAL——

I’m working with active record in pure ruby (without Rails), and I’m literally getting crazy with this.
This is my code

class Enviroment < ActiveRecord::Base
    #self.table_name = 'enviroments'
    self.connection.create_table(:enviroments, :force=>true) do |t|
        t.column :name, :string, :default=>'env-'+ (last.id-1).to_s
        t.column :ssh, :string, :default=>nil
    end
end

and here the error:

ActiveRecord::StatementInvalid: Could not find table 'enviroments'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.2.3/lib/active_record/connection_adapters/sqlite_adapter.rb:465:in `table_structure'

if I useself.table_name = 'enviroments' still not working. I’ve updated the gems and neither.
I’m newbie with ruby and databases, but I can’t understand this problem, I think this same code worked in the past :S

  • 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-06-01T11:40:44+00:00Added an answer on June 1, 2026 at 11:40 am

    Finally, this was my solution:

    class Enviroment < ActiveRecord::Base
    after_create :create_default
    
    private
    def create_default
        if name == nil
            s = 'env-' + self.id.to_s
            self.name = s
            self.save
        end
    end
    
    end
    
    class CreateSchema < ActiveRecord::Migration
    create_table(:enviroments, :force=>true) do |t|
        t.column :name, :string, :default=>nil
        t.column :ssh, :string, :default=>nil
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I recently ran against a very interesting site that expresses a very interesting idea
All of my code is on my SVN, but I want some of it
&mdash; or &#8212; Is there a difference between these? Is one better-supported than the
I am trying to create a modal window for my application, but unfortunately I
I'm using a DatePicker ( org.apache.wicket.extensions.yui.calendar.DatePicker — Javadoc ) in a form. The form
I have a fairly mundane piece jQuery that toggles a div's visibility when a
I'm having a simple problem toggling between +/- characters which prepend a link which
I am currently running into a problem where an element is coming back from
I'm including a local class that requests a file from a remote server. This

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.