Domanda

I'm trying to insert data with migration and don't understand what's wrong with this code:

def change

  create_table :sourcebuster_settings do |t|
    t.integer :session_length
    t.boolean :use_subdomains, default: false
    t.string :main_host

    t.timestamps
  end
  Sourcebuster::Setting.create session_length: 30,
                               use_subdomains: false
end

create_table works fine, but no data inserted after migration. No errors in console.

Previous migrations with the same method of data insertions works fine also. Problem only with this one.

È stato utile?

Soluzione

I got it. In my setting model:

  before_save { self.main_host = main_host.gsub(/(http:|https:|www\.|:|\/)/,'').downcase if self.main_host }

  validates_presence_of :main_host, if: lambda { self.use_subdomains }
  validates :main_host, format: { with: VALID_HOST_REGEX }, allow_blank: true

Added allow_blank: true to main_host validation.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top