GithubHelp home page GithubHelp logo

hayeah / active_record_no_table Goto Github PK

View Code? Open in Web Editor NEW

This project forked from neerajsingh0101/active_record_no_table-10-abc2

1.0 4.0 1.0 83 KB

Validate a model using validation tools provided by ActiveRecord even though the model does not have a corresponding table

active_record_no_table's Introduction

active_record_no_table

Introduction

Using ActiveRecord validation utilitites is difficult if you do not have a table for your model. This gem makes it easy to use validation tools even if the model does not have a corresponding table.

This gem works with Rails 2.1 and higher.

How to install

  
gem sources -a http://gems.github.com
sudo gem install neerajdotname-active_record_no_table
  
  
config.gem "neerajdotname-active_record_no_table", 
           :lib => active_record_no_table',
           :source => 'http://gems.github.com'                                        
  

How to use this gem

  
class Contact  < ActiveRecord::NoTable
  attr_accessor :name, :email, :body, :subject
  validates_presence_of :name, :email, :body
  validates_format_of   :email,     
                        :with => Format::EMAIL,
                        :message => "^The email address is not valid. Please enter a valid email address.",
                        :if => Proc.new { |record| record.email.not_blank?}   
end

# in controller
@contact  = Contact.new(params[:contact])
if @contact.valid?
  ...
end

# using script_console
>> c = Contact.new
=> #
>> c.valid?
=> false
>> c.errors.full_messages
=> ["Please enter your name", "Please enter the message that you want to send", "Please enter your email address"]

Feedback

Email me: neerajdotname [at] gmail (dot) com

source code

http://github.com/neerajdotname/active_record_no_table/tree/master

Author Blog

http://www.neeraj.name

License

MIT

Copyright (c) 2009 neerajdotname

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.