Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails Custom Validators

Rails Custom Validators

Talk feita em um encontro do Meetup Floripa On Rails.
O código utilizado na apresentação está disponível no Github: https://github.com/marcelinol/custom-validator-example

Luciano Medeiros

September 15, 2015
Tweet

More Decks by Luciano Medeiros

Other Decks in Technology

Transcript

  1. > p = Person.create(name: 'Nome', personal_site: 'http://pudim.com.br') (0.2ms) begin transaction

    => (...) (0.1ms) rollback transaction => (...) > p.errors => #<ActiveModel::Errors:0x007fa06fd7c370 @base=#<Person id: nil, name: "Nome", email: nil, personal_site: "http://pudim.com.br", created_at: nil, updated_at: nil>, @messages={:email=>["can't be blank"]}> >
  2. > p = Person.create(name: 'Nome', email: '[email protected]', personal_site: 'xunda') (0.2ms)

    begin transaction => (...) (0.1ms) rollback transaction => (...) > p.errors => #<ActiveModel::Errors:0x007fa06ff84618 @base=#<Person id: nil, name: "Nome", email: "[email protected]", personal_site: "xunda", created_at: nil, updated_at: nil>, @messages={:personal_site=>["Formato de site inválido"]}> > > p = Person.create(name: 'Nome', email: '[email protected]', personal_site: 'xunda') (0.2ms) begin transaction => (...) (0.1ms) rollback transaction => (...) > p.errors => #<ActiveModel::Errors:0x007fa06ff84618 @base=#<Person id: nil, name: "Nome", email: "[email protected]", personal_site: "xunda", created_at: nil, updated_at: nil>, @messages={:personal_site=>["Formato de site inválido"]}> >
  3. > p = Person.create(name: 'Nome', email: '[email protected]', personal_site: 'xunda') (0.2ms)

    begin transaction => (...) (0.1ms) rollback transaction => (...) > p.errors => #<ActiveModel::Errors:0x007fa06ff84618 @base=#<Person id: nil, name: "Nome", email: "[email protected]", personal_site: "xunda", created_at: nil, updated_at: nil>, @messages={:personal_site=>["Formato de site inválido"]}> >
  4. SIM