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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:09:49+00:00 2026-05-27T20:09:49+00:00

I read a few other posts on this subject and am still confused. In

  • 0

I read a few other posts on this subject and am still confused. In my seeds.rb I call delete and create on the model without any issues… when I get to the custom methods I created I get an undefined method error. The create and delete_all work fine when I comment out the name_gen and ssn_gen rows.

Also, this is Rails 3.1.1 on Ruby 1.8.7

Update: should have also mentioned I get the same issue if I change the create to new and move the name_gen sections to something like @sample_data_set.officialFirstName = SampleDataSet.name_gen

Error: undefined method `name_gen’ for #

Command for rake: bundle exec rake db:seed RAILS_ENV=development --trace

seeds.rb

SampleDataSet.delete_all

@sample_data_set = SampleDataSet.new (
      :campusNum               => "96",
      :dateOfBirth             => "1981-10-09",
      :gender                  => "M",
      :officialMiddleInitial   => "L",
      :addressLine1            => "PO BOX 9",
      :addressLine2            => "", 
      :city                    => "WOODLAND",
      :state                   => "GA",
      :zipCode                 => "31836",
      :homeAreaCode            => "706",
      :homePhoneNumber         => "6742435",
      :homePhoneCountryCode    => "US",
      :workAreaCode            => "706",
      :workPhoneNumber         => "6742435",
      :workPhoneCountryCode    => "US",
      :usCitizen               => true,
      :financialAid            => true,
      :previousDegree          => "ADN",
      :region                  => "MAIN",
      :program                 => "AAPSY",
      :version                 => "012",
      :team                    => "TEAM 3236A",
      :enrollmentUserId        => "SSGROTH",
      :revCampusOid            => "1627",
      :executingUserId         => "QROBINSO",
      :totalDeclaredExtCredits => "1",

      #generating some default values for the gen fields... except IRN
      :officialFirstName => SampleDataSet.name_gen,
      :officialLastName => SampleDataSet.name_gen,          
      :enrollAgreeSignDate => Date.today.strftime('%Y-%m-%d'),
      :scheduledStartDate => Date.tomorrow.strftime('%Y-%m-%d'),
      :ssn => SampleDataSet.ssn_gen.to_s
      )

@sample_data_set.emailAddresses = officialFirstName + "." + officialLastName + "@aaaa.phoenix.edu"

,

SampleDataSet model

class SampleDataSet < ActiveRecord::Base

  #Random info generation
  def name_gen(*prepend)
    #Random character generation piece I found on Stackoverflow with 102 upvotes
    character_map =  [('a'..'z'),('A'..'Z')].map{|i| i.to_a}.flatten
    name  =  (0..8).map{ character_map[rand(character_map.length)]  }.join

    if prepend.nil?
      return name
    else
      return prepend.to_s + "_" + name
    end
  end

  def ssn_gen
    #broke this out as its own method in case someone wants some logic later on
    ssn = Random.rand(1000000000) + 99999999
    return ssn
  end

end
  • 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-27T20:09:49+00:00Added an answer on May 27, 2026 at 8:09 pm

    In order to call some method directly on class like that:

    SampleDataSet.name_gen
    

    instead of calling it on an instance of that class (as regular methods are called) like that:

    a = SampleDataSet.new
    a.name_gen 
    

    you should define that method as a class method.

    You can do it using self.name_gen instead of name_gen in method definition like that:

    class SampleDataSet < ActiveRecord::Base
    
      # Random info generation
      def self.name_gen(*prepend)
        # Random character generation piece I found on Stackoverflow with 102 upvotes
        character_map = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
        name = (0..8).map { character_map[rand(character_map.length)] }.join
    
        if prepend.nil?
          return name
        else
          return prepend + "_" + name
        end
      end
    
      def self.ssn_gen
        # broke this out as its own method in case someone wants some logic later on
        ssn = Random.rand(1000000000) + 99999999
        return ssn
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read a few posts on this but I'm still confused. I have this
I've read a few other posts like this one about avoiding repetition in Java
I've read a few other questions that seem similar but I'm still very confused,
I have read a few of the other questions on this and I still
enter code hereI have read a few other posts like mine, but still no
I've read the article (and few others on the subject), but still can't figure
I have read few articles about table partioning but still I am bit confused
This question seems similar to those asked in a few other posts: here and
Before we start, I've read more than a few other posts here related to
i've read a few other post on here regarding this topic. I understand that

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.