项目作者: hardpixel

项目描述 :
ActiveRecord models without database tables.
高级语言: Ruby
项目地址: git://github.com/hardpixel/tableless.git
创建时间: 2017-10-16T08:10:09Z
项目社区:https://github.com/hardpixel/tableless

开源协议:MIT License

下载


Tableless

Create models that are not bound to the database and take advantage of the ActiveRecord features, such as validation, relationships, etc.

Gem Version
Build
Maintainability

Installation

Add this line to your application’s Gemfile:

  1. gem 'tableless'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install tableless

Usage

Define a model like this:

  1. class ContactMessage < ActiveRecord::Base
  2. include Tableless
  3. attribute :name, :string
  4. attribute :email, :string
  5. validates :name, :email, presence: true
  6. end

You can now use the model in a view like this:

  1. <%= form_for :message, @message do |f| %>
  2. Name: <%= f.text_field :name %>
  3. Email: <%= f.text_field :email %>
  4. <% end %>

And in the controller:

  1. def message
  2. @message = ContactMessage.new(params[:message])
  3. if @message.valid?
  4. # Process the message...
  5. end
  6. end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run bundle exec rake install.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/tableless.

License

The gem is available as open source under the terms of the MIT License.