Executing a ruby script from the Rails console
<pre><code>Rails 3.2
</code></pre>

<p>I have a running rails application, with a Company MVC.</p>

<p>in the models/company.rb, I have the following method:</p>

<pre><code>def save_company_pay_num
  return false unless self.valid?
  create_company_pay_num if self.company_pay_num.blank?
  res = save_check_company_pay_num
  unless res[0]
    errors.add(:set_company_pay_num, res[1].try{|r| r.split(':')[1].strip.capitalize})
    return false
  end
  true
end 
</code></pre>

<p>I have about 1,000 companies, that need to have their pay numbers re-issued.</p>

<p>Is there a way, from the rails console (rails c), to execute a file, something like:</p>

<pre><code>reset_pay_num.rb

company_ids=[
  '1',
  '2',
  '3',
  ...
]

company_ids.each do |c|
  company = Company.find(c)
  company.save_company_pay_num
end
</code></pre>