문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top