Skip to content

Validation from class attributes #380

@radvc

Description

@radvc

Right now Im using virtus in my rails project but Im having a problem to validate class attributes.
This are the codes:

class NewAccountForm
 include Virtus
 extend ActiveModel::Naming
 extend ActiveModel::Conversion
 extend ActiveModel::Validations
  
  attribute :username, String
  attribute :user_type, String
  attribute :profile, ProfileAttribute
 
  validates_presence_of :username, :user_type
end
class ProfileAttribute
 include Virtus
 extend ActiveModel::Validations
 
 attribute :firstname, String
 attribute :middlename, String
 attribute :lastname, String
 attribute :email, String

  validates_presence_of :firstname, :middlename, :lastname, :email
end

my form Im using client_side_validation gem

= form_for @account, url: accounts_path, validate: true do |f|
   = f.text_field :username
   = f.fields_for :profile do |profile|
      = profile.text_field :firstname
      = profile.text_field :middlename
      = profile.text_field :lastname

I set validations in ProfileAttribute class but it didn't work. How can I get the validation from class attribute?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions