Validation of virtual attributes in Ruby on Rails

前端 未结 1 1089
隐瞒了意图╮
隐瞒了意图╮ 2021-01-18 05:30

I am running Ruby (1.9.3) on Rails (3.2.0) and having a problem with the validation of virtual attributes.

I have a Flight model that represents a fligh

相关标签:
1条回答
  • 2021-01-18 06:10

    I think you are going the right way with the before_validation callback.

    You can validate virtual attributes like every normal attribute. So all you need is just some validation in the model. Try this:

    validates :departure_airport, presence: true
    validates :arrival_airport, presence: true
    

    this should add an error to the objects errors and the error should be displayed in your form...

    0 讨论(0)
提交回复
热议问题