I have a problem with ruby on rails validation total_book_toy.rhtml ===============<%= 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. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060627/465106a2/attachment.html
Use validates_uniqueness_of in the model. http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000816 If you need more control just define your own validate method. -Jonathan On 6/27/06, Budi Irawan <manteez8@gmail.com> wrote:> I have a problem with ruby on rails validation > > total_book_toy.rhtml > ===============> <%= 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. > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Hmm.....but these text_field are not related with active record and database so we can''t use active record validation with its error_messages, can we? in other words, I have not them in my database. Pls, help me. On 6/27/06, Jonathan Viney <jonathan.viney@gmail.com> wrote:> > Use validates_uniqueness_of in the model. > > http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000816 > > If you need more control just define your own validate method. > > -Jonathan > > On 6/27/06, Budi Irawan <manteez8@gmail.com> wrote: > > I have a problem with ruby on rails validation > > > > total_book_toy.rhtml > > ===============> > <%= 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. > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060712/77d63468/attachment.html
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 << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null) end column :name, :string column :email_address, :string column :message, :string validates_presence_of :name, :email_address end -Jonathan. On 7/12/06, Budi Irawan <manteez8@gmail.com> wrote:> Hmm.....but these text_field are not related with active record and database > so we can''t use active record validation with its error_messages, can we? > > in other words, I have not them in my database. > > Pls, help me. > > > On 6/27/06, Jonathan Viney <jonathan.viney@gmail.com> wrote: > > Use validates_uniqueness_of in the model. > > > http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000816 > > > > If you need more control just define your own validate method. > > > > -Jonathan > > > > On 6/27/06, Budi Irawan <manteez8@gmail.com> wrote: > > > I have a problem with ruby on rails validation > > > > > > total_book_toy.rhtml > > > ===============> > > <%= 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. > > > > > > > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >