Validations for Non Active Record Models.
Ruby
Switch branches/tags
Nothing to show
Pull request Compare This branch is 1 commit ahead, 9 commits behind cs:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
MIT-LICENCE
README
Rakefile
active_form.gemspec
init.rb

README

Model
===

class ContactForm < ActiveForm
  attr_accessor :name, :institution, :email, :contact_number, :address, :purpose
  validates_presence_of :name, :email, :address, :purpose
  validates_length_of :email, :within => 6..100, :unless => Proc.new {|m| m.email.blank?}
end 

Controller
===
def show
  @contact_form = ContactForm.new
end

def send_contact_form
  @contact_form = ContactForm.new params[:contact_form]

	if @contact_form.valid?
		#...
	else
		render :action => "show"
	end
end

Form
===
- form_for @contact_form, :url => send_contact_form do |f|
  = f.error_messages
  = f.text_field :name
  = f.text_field :institution
  = f.text_field :email
  = f.text_field :contact_number
  = f.text_field :address
  = f.select :purpose, ["", "First", "Second"]
  = f.submit "Request"