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

  • Home
  • SEARCH
  • 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 6760411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:03:40+00:00 2026-05-26T14:03:40+00:00

In my rails app, i am using a legacy database. class Expression < ActiveRecord::Base

  • 0

In my rails app, i am using a legacy database.

class Expression < ActiveRecord::Base
set_table_name "EXPRESSION"
set_primary_key "EXP_ID"

belongs_to :sub, :foreign_key => "EXP_SUB_FK"

end

To save an entry in the ‘EXPRESSION’ table, i am using the following code in my controller method:

@expression = Expression.create(
                        :EXP_ID => 7,
                        :EXP_SUB_FK => 99991886,
                        :EXP_STRENGTH => 'strong',
                        :EXP_ADDITIONAL_STRENGTH => 'intense',
                        :EXP_COMPONENT_ID => 43444
                       )

I have to manually set the EXP_ID each time i save an entry (i will get the id from another table), but the above code does not save the EXP_ID. All the other values are saved except for the EXP_ID.

If i comment out ‘set_primary_key “EXP_ID”‘ in the Expression model, it works but i need to define EXP_ID as primary key.
Is there a way of allocating a value for a primary key when saving an entry to the dbase?

I would be grateful if anyone can provide me with some hint.

  • 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-26T14:03:41+00:00Added an answer on May 26, 2026 at 2:03 pm

    Set the EXP_ID in a before_save filter defined in the the Expression model.

    UPDATE:

    Added Sample:

    before_save :set_exp_id
    def set_exp_id
      self.exp_id = 5555555
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an Ruby on Rails app using a legacy database. The problem I'm
I am using Amazon S3 to back up my Rails app's mysql database. And
I've got a Rails app that'll be sitting on top of a legacy database
I've developed a web interface for a legacy (vendor) database using Ruby on Rails.
I'm having trouble connecting to the database for my Rails app using pgAdmin. I
I have already implemented some AJAX pagination in my Rails app by using the
I am developing a web app (using rails) that I will be launching within
I'm using webrick to run my rails app in development mode. The page includes
I am using ActiveScaffold in a Ruby on Rails app, and to save space
I'm using Authlogic with my Ruby on Rails App. I would like user to

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.