DataMapper Forms Gem
dm-forms is a Ruby gem aimed at providing a framework-agnostic form library tied to DataMapper models for simple, easy, clean style-able form markup. A strong framework-agnostic library for DataMapper proves to be useful among many other frameworks such as Sinatra.
DataMapper Forms Features
- Integrates with DataMapper
- Fast; over 1000 elements in 0.1 seconds (rake benchmark)
- Error reporting
- Handles restful HTTP verbs (put, and others are stored in hidden _method field)
- Provides low-level form elements uncoupled from DataMapper
Installation
Currently the gem is only available on Github due to being relatively far from an
official release. For feedback, installation, or contribution visit http://github.com/visionmedia/dm-forms
Login Form Example
errors_for @user
form_for @user, :action => '/user' do |f|
f.textfield :name, :label => 'Name'
f.textfield :email, :label => 'Email'
f.submit :op, :value => 'Update'
end<ul class="messages error">
<li>Name has an invalid format</li>
</ul>
<form action="/user" method="post" id="form-user">
<input type="hidden" name="_method" value="put" />
<label for="name">Name:</label>
<input type="textfield" class="error form-textfield form-name" name="name" />
<label for="email">Email:</label>
<input type="textfield" class="form-textfield form-email" name="email" />
<input type="submit" class="form-submit form-op" value="Update" name="op" />
</form>Benchmarks
The performance shown in current benchmarks is certainly acceptable, however we will be aiming
to decrease these numbers once the majority of functionality is complete.
Single element
user system total real
10 elements 0.000000 0.000000 0.000000 ( 0.000837)
100 elements 0.010000 0.000000 0.010000 ( 0.007972)
1000 elements 0.070000 0.010000 0.080000 ( 0.082535)
Capture elements within a fieldset
user system total real
10 elements 0.010000 0.000000 0.010000 ( 0.000970)
100 elements 0.040000 0.000000 0.040000 ( 0.051861)
1000 elements 0.070000 0.000000 0.070000 ( 0.070761)
Entire forms
user system total real
Login 0.000000 0.000000 0.000000 ( 0.000439)
Register 0.000000 0.000000 0.000000 ( 0.000962)
Entires form with #form_for
user system total real
User 0.000000 0.000000 0.000000 ( 0.001012)Bookmark/Search this post with:
Delicious
Digg
StumbleUpon
Reddit
Facebook