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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:07:22+00:00 2026-06-16T23:07:22+00:00

I have this static method for a model, which is creating multiple records. This

  • 0

I have this static method for a model, which is creating multiple records. This method is called when saving the parent, the data for creating appropriate n child records is passed to this method (new_record) which then iterates through the array passed to it, and creates the child records.

Job has many Job Activities. This method new_record belongs to job_activities model and is invoked in job_controller, when saving job record. Basically trying to implement two models in a single form. Job “has_many” job_activities, and Job_activites “belongs_to” a job.

Here’s what I have put together so far –

       def self.new_record(sk_job_id, activities_list)
        activities_list.each do | act |
          puts "AAAAAAAAAAAAAAAAAAAAAAA creating a new record for "+act.inspect+" and " + sk_job_id.to_s
            ja = JobActivity.new
            puts "Job ID SK = "+sk_job_id.to_s
            puts "act = "+act
            puts "Record before assignment "+ ja.inspect
            ja.job_id_sk = sk_job_id
            ja.job_activity = act
            ja.created_by  = "raghav"
            ja.updated_by  = "raghav"
            puts "Record after assignment "+ ja.inspect            
            ja.save!
            puts "record after saving "+ ja.inspect
        end
      end

Weird thing happening is, that the before and after assignment state of the object ja, reflects the assignment of “created_by” but not of job_id_sk and job_activity…

And, as suggested, I implemented the save! but that didnt raise any exceptions.. its still quite silently behaving what its doing… 🙁

AAAAAAAAAAAAAAAAAAAAAAA creating a new record for "ACT1" and 40
Job ID SK = 40
act = ACT1
Record before assignment #<JobActivity id: nil, job_id_sk: nil, job_activity: nil, created_by: nil, updated_by: nil, created_at: nil, updated_at: nil>

Record after assignment #<JobActivity id: nil, job_id_sk: nil, job_activity: nil, created_by: "raghav", updated_by: "raghav", created_at: nil, updated_at: nil>

record after saving #<JobActivity id: 13, job_id_sk: nil, job_activity: nil, created_by: "raghav", updated_by: "raghav", created_at: "2013-01-08 02:22:30", updated_at: "2013-01-08 02:22:30">

However, when I go and check the mysql table where the data should have been saved, I see that only NULL values have been passed in…

mysql> select job_id_sk, job_activity from job_activities;
+-----------+--------------+
| job_id_sk | job_activity |
+-----------+--------------+
|      NULL | NULL         |
|      NULL | NULL         |
|      NULL | NULL         |
|      NULL | NULL         |
|      NULL | NULL         |
+-----------+--------------+
5 rows in set (0.00 sec)

Am I missing something somewhere ?

  • 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-16T23:07:24+00:00Added an answer on June 16, 2026 at 11:07 pm

    Found the problem, and the solution…

    I was using attr_accessor for the model, whereas I should have been using attr_accessible…

    Response from James on this question helped me..

    Called .save on a ruby object is only passing nil for all strings

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

Sidebar

Related Questions

So I have a simple method called Invert : public static void Invert(this bool
I have a business model which consists of a parent/child relationship (Identifier/IdentifierValue) and also
I have a static method 'findAll' on a model which basically gets all rows
I currently have this working but it requires me to have a static method
I have this method: internal static void AssignNewArrayItem(ref Xml.CLASSNAME[] Items, Xml.CLASSNAME Item) { if
I have a method that looks like this: public static String escape(String text) {
I have a method private static DataTable ParseTable(HtmlNode table) and sometimes this method has
I have a page with this method in CreateTicket.aspx.cs: [WebMethod()] public static string Categories()
the ToSelectList method I have: public static IList<SelectListItem> ToSelectList<T>(this IEnumerable<T> itemsToMap, Func<T, string> textProperty,
I have a select method for ObjectDataSource: public static IEnumerable<Model.Domain.Theme> Select() { var cycleRepo

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.