Chronorails¶ ↑
Chronorails handles adding virtual attributes to your models (with suitable validations, etc) allowing you to set date and duration fields with natural language text.
Installation¶ ↑
gem install chronorails
Usage¶ ↑
For a hypothetical Rails model:
class RomanticMeeting < ActiveRecord::Base attr_accessible :length, :start # Integer and DateTime DB fields, respectively include Chronorails::ChronicAccessors chronic_field :start, :required => true chronic_duration_field :length end
…include the accessors module, and configure Chronorails to start wrap your attributes with either Chronic or Chronic Duration virtual attributes.
Then in your form:
<%= f.text_field :chronic_start %> <%= f.text_field :chronic_duration_length %>
…you can use the virtual attributes for your fields, entering natural language date and duration information that will be parsed into the regular fields (or will generate validation errors).
The ‘required’ option prevents setting the attributes with blank values; the ‘validates’ option controls the generation of validators (defaults to true) and the ‘accessible’ option controls the generation of Rails 3 ‘attr_accessible’ calls (also defaults to true.)
Testing¶ ↑
git clone git@github.com:simonhildebrandt/chronorails.git cd chronorails bundle install cd spec/dummy rake db:create rake db:migrate rake db:test:prepare cd - bundle exec rspec spec
Contribute¶ ↑
-
Fork
-
Hack
-
Test
-
Pull request :)
License¶ ↑
Copyright © 20013 Simon Hildebrandt, released under the MIT license