Skip to content

Accepts nested attributes for support for Ripple (Riak ORM)

License

Notifications You must be signed in to change notification settings

bkaney/ripple-anaf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ripple-anaf

This is inspired and similar implementation to the ‘accepts_nested_attributes` functionality found in AR. This allows the use update attributes and create new child records through the parent. It also allows the use of the `fields_for` form view helper, using a presenter pattern.

To enable in the model, call the class method, using the same relationship as defined in the ‘one` or `many`.

class Shipment
  include Ripple::Document
  property :identifier, String

  one :box
  many :addresses
  many :checkpoints

  accepts_nested_attributes_for :box, :addresses
  accepts_nested_attributes_for :checkpoints, :allow_destroy => true, :reject_if => proc{|attrs| attrs['signed_off'].blank? }
end

Now, you can do things like this:

Shipment.create(
  :identifier => '1Z0001', 
  :box_attributes => { :weight => 1.4 }, 
  :addresses_attributes => [ { :street => "Main Street" } ] 
)

And in your views you can use fields_for:

<%= form_for(@shipment) do |f| %>

  <%= f.text_field :identifier %>

  <%=  f.fields_for :box do |ff| %>
    <%= ff.text_field :weight %>
  <% end %>

<% end %>

Installation

Currently in pre-release for testing.

gem install ripple-anaf --pre

Supported Features

  • Same DSL for linked and embedded documents

  • :reject_if

  • :allow_destroy

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Brian Kaney. See LICENSE for details.

About

Accepts nested attributes for support for Ripple (Riak ORM)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages