简体   繁体   中英

Rails 4 : Validate fields from form without model

I need to validate a form but I don't want to use validations from model, because fields come from many models.

I'd like to do something like request from Laravel https://laravel.com/docs/5.7/validation#creating-form-requests

You can use ActiveModel::Validations like this

class MyClass
  include ActiveModel::Validations

  validates :email, presence: true
  validates :message, presence: true
end

It will act as a normal model.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM