Not Active Record Model Validation

I have a problem with ruby on rails validation


<%= text_field ‘book1’, ‘title1’ %>
<%= text_field ‘book2’, ‘title2’ %>

I want to validate these text_field so user can’t insert same title.
However, I was stuck how to do it.
Or maybe you have another way how to do it.

Any suggestion, please?

Thank you so much.

Use validates_uniqueness_of in the model.

If you need more control just define your own validate method.


Hmm…but these text_field are not related with active record and
so we can’t use active record validation with its error_messages, can

in other words, I have not them in my database.

Pls, help me.

Either create a table and just don’t save the object, or use a
tableless model. Here’s an example:

class Contact < ActiveRecord::Base
def self.columns() @columns ||= []; end
def self.column(name, sql_type = nil, default = nil, null = true)
columns <<,
default, sql_type.to_s, null)

column :name, :string
column :email_address, :string
column :message, :string

validates_presence_of :name, :email_address



I have been looking for a way to do table-less ActiveRecords for a

Where would I find complete documentation for this technique ?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs