lundi 28 mai 2018

How to use create! method on a class with a constructor that takes 1 argument

I have a class look like this (simplified)

class Timereg < ActiveRecord::Base

  def initialize(hour_id)
    super()
    self.hour_id = hour_id
    self.status = -2
    self.slug = SecureRandom.uuid.to_s
  end
end

When using it like this

Timereg.new(1)

All good

But how can I use it with this

Timereg.create!

I cant figure out the syntax I keep getting

ArgumentError: wrong number of arguments (2 for 1)

Aucun commentaire:

Enregistrer un commentaire