Git Product home page Git Product logo

chronorails's Introduction

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 [email protected]: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

chronorails's People

Contributors

james avatar simonhildebrandt avatar

Watchers

 avatar  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.