Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation from class attributes #380

Open
radvc opened this issue Jul 10, 2017 · 0 comments
Open

Validation from class attributes #380

radvc opened this issue Jul 10, 2017 · 0 comments

Comments

@radvc
Copy link

radvc commented Jul 10, 2017

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?

@radvc radvc changed the title Valiation of class attributes Valiation from class attributes Jul 10, 2017
@radvc radvc changed the title Valiation from class attributes Validation from class attributes Jul 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant