I am trying to validate a form that''s not using a database. The class (validateable.rb) comes from Rails Recipes and I am not sure how I can get the validation to work with my controller and view. It''s probably trivial problem but I new to RoR as well as Ruby. /lib/validateable.rb from rails recipes ----------------------------------------------------------------------------- module Validateable [:save, :save!, :update_attribute].each{|attr| define_method(attr){}} def method_missing(symbol, *params) if(symbol.to_s =~ /(.*)_before_type_cast$/) send($1) end end def self.append_features(base) super base.send(:include, ActiveRecord::Validations) end end /app/controllers/app_controller.rb ----------------------------------------------------------------------------- class AppController < ApplicationController def submit if request.post? ContactMailer.deliver_contact_message(params[:name], params[:email], params[:message]) flash[:notice] = "Message sent!" redirect_to :action => ''contact'' end end /app/views/contact_mailer/contact.rhtml ----------------------------------------------------------------------------- <h1>Contact Page</h1> <%= render :partial => ''navigation'' %> <hr /> <% if flash[:notice] -%> <div id="notice"><%= flash[:notice] %></div> <% end -%> <%= error_messages_for "contact" %> <%= start_form_tag(:action => ''submit'') %> <p> <label for="contact_name">Name</label> <br /> <%= text_field("contact", "name") %> </p> <p> <label for="contact_email">E-mail</label> <br /> <%= text_field("contact", "email") %> </p> <p> <label for="contact_message">Message</label> <br /> <%= text_area("contact", "message") %> </p> <%= submit_tag("Send") %> <%= end_form_tag %> /app/models/contact_mailer.rb ----------------------------------------------------------------------------- class ContactMailer < ActionMailer::Base def contact_message(cust_name, cust_email, cust_message) @subject = "Hi" @body = "(#{cust_message})" @recipients = cust_email @from = "user-9IKiO1iGCm/QT0dZR+AlfA@public.gmane.org" @sent_on = Time.now end end #this is the *problem* - how do I get this to work with my controller? /app/models/contact.rb ----------------------------------------------------------------------------- class Contact include Validateable attr_accessor :email validates_presence_of :email end Thank you -- 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 -~----------~----~----~----~------~----~------~--~---
Anyone? -- 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 -~----------~----~----~----~------~----~------~--~---
Hi, I''d check http://agilewebdevelopment.com/plugins/activerecord_base_without_table to see if it helps. What if your Contact class is regular active record object (with validations, callbacks etc) but without database table beneath? Pavlo> > Anyone? >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Pavel Lysov wrote:> Hi, > I''d check > http://agilewebdevelopment.com/plugins/activerecord_base_without_table > to see if it helps. What if your Contact class is regular active record > object (with validations, callbacks etc) but without database table > beneath? > > PavloPavlo, I tried that approach. However, I prefer to use the above solution. Do you have idea what might be wrong? M -- 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 -~----------~----~----~----~------~----~------~--~---
So what happens when you call some_contact.valid? Fred -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> So what happens when you call some_contact.valid? > > FredFrederic, In IRB it works but I cannot get the error messages to show up. Any idea? MJ -- 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 -~----------~----~----~----~------~----~------~--~---