Ive followed this example of how to validate a form with a tableless model: http://rails.techno-weenie.net/tip/2005/11/19/validate_your_forms_with_a_table_less_model Ive got this example working but when validation fails the failed boxes are not highlighted in red. At the moment i have a contact details form and want to validate the information entered by the user but this will just result in sending an email, its not saving to a database table. My code in the controller is this at the moment and this works but if the validation fails it just displays the flash message i have provided, not highlighting the boxes in red. def contact @contact = Contact.new(params[:contact]) if @contact.valid? OrderMailer::deliver_send_an_email() # notice the ''deliver_'' prefix flash[:notice] = ''Query was successfully created.'' redirect_to :action => ''contactus'' else flash[:notice] = ''Query was not successfully created.'' redirect_to :action => ''contactus'' end end This my contacts model class: 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 :contact_details, :string column :subject, :string column :query, :string validates_presence_of :name, :contact_details, :query end Can anyone help me please? -- Posted via http://www.ruby-forum.com/.
I have a similar problem. Model validation seems to work fine, but my error object is empty, so the errors don''t get displayed i dont know why. I dont have any errors. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Pabloz wrote:> I have a similar problem. Model validation seems to work fine, but my > error object is empty, so the errors don''t get displayed i dont know > why. I dont have any errors.ok, i got it..i used redirect instead of render. rookie mistake ( cause i am a rookie :) ) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If you want to avoid cluttering your model definitions, you can use my plugin: http://svn.viney.net.nz/things/rails/plugins/active_record_base_without_table/ <http://svn.viney.net.nz/things/rails/plugins/active_record_base_without_table> -Jonathan On 8/17/06, John Butler <johnnybutler7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Ive followed this example of how to validate a form with a tableless > model: > > > http://rails.techno-weenie.net/tip/2005/11/19/validate_your_forms_with_a_table_less_model > > Ive got this example working but when validation fails the failed boxes > are not highlighted in red. At the moment i have a contact details form > and want to validate the information entered by the user but this will > just result in sending an email, its not saving to a database table. > > My code in the controller is this at the moment and this works but if > the validation fails it just displays the flash message i have provided, > not highlighting the boxes in red. > > def contact > @contact = Contact.new(params[:contact]) > if @contact.valid? > OrderMailer::deliver_send_an_email() # notice the ''deliver_'' > prefix > flash[:notice] = ''Query was successfully created.'' > redirect_to :action => ''contactus'' > else > flash[:notice] = ''Query was not successfully created.'' > redirect_to :action => ''contactus'' > end > end > > > This my contacts model class: > > 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 :contact_details, :string > column :subject, :string > column :query, :string > validates_presence_of :name, :contact_details, :query > end > > > Can anyone help me please? > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---