Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8879873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:03:02+00:00 2026-06-14T20:03:02+00:00

I have a message model and i have been looking at various gems/js for

  • 0

I have a message model and i have been looking at various gems/js for client side validation. I then started reading about Active Model Validations, im pretty new to rails so please forgive me for not totally understanding the documentation.

Firstly am i correct in saying that i can perform client side validation with ActiveModel Validation and set my own custom error messages

I have at the top of my message model

include ActiveModel::Validations

Further reading has identified

i should be using

 validates_with MyValidator

But this does not work as i get error message

uninitialized constant Message::MyValidator

if i place this in the model

I have also read that-

 To cause a validation error, you must add to the record‘s errors directly from within the validators message

class MyValidator < ActiveModel::Validator
def validate(record)
record.errors.add :base, "This is some custom error message"
record.errors.add :first_name, "This is some complex validation"
# etc...
end

So this is saying i can add my own custom error messages client side?

My issue at the moment is getting my head around what it is stating to do, where do i put these classes and methods etc.. If anyone can point me in the right direction i would be grateful, i really want to learn

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:03:03+00:00Added an answer on June 14, 2026 at 8:03 pm

    ActiveModel validations do not provide client side validation. If you’d like to use your Rails validators on the client side, I’d suggest the client_side_validations gem.

    If you’re having trouble getting started, I’d suggest performing a single, simple validation in your model and verifying that it works before trying to move it client-side. For example, in your Message class:

    # app/models/message.rb
    class Message
      include ActiveModel::Validations
      attr_accessor :sender
      validates :sender, presence: true
    end
    
    # in the console
    m = Message.new
    
    m.valid?                #=> false
    m.errors.full_messages  #=> ["Sender can't be blank"]
    

    Then start working with other types of validates, like length or format, then custom validations with the validate method, and then if you finally feel like you need it, a full validation class using validates_with.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been doing more client-side development, managing the UI on the client and
Here is what I've been struggling for a day... I have a Message model
Hi I have been trying to access the validation rules of an associated model
I have been very puzzled about the concept of model (entity) persistence in Symfony2.
i have a Message model and controller. and in it, i have the standard
I have been looking for hours on how to connect to my local SQL
I've been trying to create a DB model using GreenDAO. the problem started when
I have been adding error and business validation to my app, and when I
Been struggling with this for about 4 hours, I'm attempting to have a modal
I have been rebuilding my social network in code igniter and am looking for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.