Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kronn/date_checkbox
This is a rails-plugin which can create a checkbox for attributes which are datetime-fields in the database
https://github.com/kronn/date_checkbox
Last synced: about 2 months ago
JSON representation
This is a rails-plugin which can create a checkbox for attributes which are datetime-fields in the database
- Host: GitHub
- URL: https://github.com/kronn/date_checkbox
- Owner: kronn
- License: mit
- Created: 2011-05-28T13:15:20.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2024-10-15T10:31:32.000Z (3 months ago)
- Last Synced: 2024-11-16T21:36:06.825Z (about 2 months ago)
- Language: Ruby
- Homepage:
- Size: 18.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- License: MIT-LICENSE
Awesome Lists containing this project
README
= DateCheckbox
This is a rails-plugin which can create a checkbox for attributes which are
datetime-fields in the database. So, if you want to store the date when a user
appected some terms or received some goods, but want to circumvent the need of
selecting the proper date and time from 6 dropdowns, you can just use this
plugin.It creates some wrapper-methods on the model for the attributes you specify and
provides a form-helper which uses these. The model-methods also work with
standard checkbox-tags.Personally, I do not want to go through the hassle of selecting the proper date
and time from 6 dropdowns. I just want to check a checkbox and have my app to
the rest. In many cases, this is even required security- or permission-wise.While this functionality is fairly easy to implement for one datetime-field
(like terms_accepted_at), I don't like to repeat this code.Therefore, I put this rails-plugin together.
A neat side-effect is, that I went and created a form-helper and added some
useful model methods along the way.== Installation
Just add
gem 'date_checkbox'
to your Gemfile. If your not using Bundler and Rails3 by now, we can still be
friends, but thats about it.== Example
# app/models/user.rb
class User < ActiveRecord::Base
has_date_checkbox :terms_accepted_at
endThis adds the following three methods to the user-model:
* terms_accepted # returns "0" or "1"
* terms_accepted= # "1" sets to the current Time, otherwise sets to nil
* terms_accepted? # true or falseYou can use it the form-helper like this:
# app/views/users/_form.html.erb
<%= form_for @user do |f| %>
<%= f.date_checkbox :terms_accepted_at %>
<% end -%>The date_checkbox appends the date form the database if its selected. If you do
not want that, simply usef.checkbox :terms_accepted
This is what f.date_checkbox uses anyway.
== Notes
Currently, I hook into ActionPack/ActionView directly, which is dirty by saves
you from declaring a different FormBuilder for every form. I also refrained
from changing the default-form builder for you because I don't want to conflict
with other form-extensions you might want to use.If everything goes south, you can still use the model-methods. This is not (by
any means) über-rocket-science. It's just convenient.Your turn.
== Development
Cpt. Obvious told me the following:
This is open-sourced on github.
You can contribute by sending pull-requests or just opening issues.He is obviously right and you also knew that. Any feedback is appreciated.
Copyright (c) 2011 Matthias Viehweger, released under the MIT license