Giter Site home page Giter Site logo

acts_as_tableless's Introduction

ActsAsTableless

Create tableless activerecord objects that support associations and validations.

Install:

  1. add gem 'acts_as_tableless' to your gemfile

  2. run bundle install

  3. add acts_as_tableless to a activerecord model

Usage:

 class User < ActiveRecord::Base
   has_many :shapes
   has_many :user_colors
   has_many :colors, :through => :user_colors
   has_one :size
   belongs_to :number
   attr_accessible :name, :number_id, :letter_id
 end

 class Color < ActiveRecord::Base
   acts_as_tableless
   column :id, :integer
   column :name, :string
   attr_accessible :id, :name
   belongs_to :user_colors
 end

 class Letter < ActiveRecord::Base
   acts_as_tableless
   column :id, :integer
   column :name, :string
   column :user_id, :integer
   attr_accessible :id, :name, :user_id
   has_and_belongs_to_many :users
 end

 class Number < ActiveRecord::Base
   acts_as_tableless
   column :id, :integer
   column :name, :string
   attr_accessible :id, :name
   has_many :users
 end

 class Shape < ActiveRecord::Base
   acts_as_tableless
   column :id, :integer
   column :name, :string
   column :user_id, :integer
   attr_accessible :id, :name, :user_id
   belongs_to :user
 end

 class Size < ActiveRecord::Base
   acts_as_tableless
   column :id, :integer
   column :name, :string
   column :user_id, :integer
   attr_accessible :id, :name, :user_id
   belongs_to :user
 end

 class UserColor < ActiveRecord::Base
	  belongs_to :user
	  belongs_to :color
	  attr_accessible :user_id, :color_id
 end

Examples:

@user = User.create(:name => "User")

@user.shapes.create(:name => "Octagon") #=> #<Shape id: 1, name: "Octagon", user_id: 1>

@user.colors << Color.create([{:name => "Green"},{:name => "Blue"}]) #=> [#<Color id: 1, name: "Green">, #<Color id: 2, name: "Blue">]

@user.size.create(:name => "Large") #=> #<Size id: 1, name: "Large", user_id: 1>

@user.number = Number.create(name: "One") #=> #<Number id: 1, name: "One">

More stuff in the test file.

Notes:

This gem relies on String#singularize which is known to have some problems. To correct errors such as:

uninitialized constant Statu (NameError)

please add something similar to:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.singular("statuses", "status")
  inflect.singular("status", "status")
end

to your environment.rb file before the Application.initialize! line

acts_as_tableless's People

Contributors

chaunce avatar

Watchers

James Cloos avatar tilman avatar

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.