Code Monkey home page Code Monkey logo

acts_as_datable's Introduction

= acts_as_datable plugin

	acts_as_datable allow you to display a year/month based archive list on a given model

== Install

   `script/plugin install git://github.com/cedricbousmanne/acts_as_datable.git`

== Usage

	In your model (basic):

	class Post < ActiveRecord::Base
		acts_as_datable
	end
	
	You can also pass some arguments to the method : 
	
	* <tt>:on</tt> 
	* <tt>:order</tt> 
	* <tt>:conditions</tt> 
	
	Examples: 
	
	acts_as_datable :conditions => ["enabled = ?", true]
	acts_as_datable :conditions => ["enabled = ?", true], :on => :published_at
	acts_as_datable :conditions => ["enabled = ?", true], :on => :published_at, :order => "ASC"

	In your view:
	
	Display year/month based archive list:
	<%= date_based_archive(Post.collection) %>
	
	Display a single year based archive list (ie: only year 2000):
	<%= date_based_archive(Post.months_of_year(2000)) %>

=== Produces

   <ul>
     <li class='actsasdatable-year'><a href="/posts/2010">2010</a>
       <ul class='actsasdatable-months'>
         <li class='actsasdatable-month'><a href="/posts/2010/1">january</a></li>
         <li class='actsasdatable-month'><a href="/posts/2010/2">february</a></li>
         <li class='actsasdatable-month'><a href="/posts/2010/3">march</a></li>
       </ul>
     </li>
   </ul>
   
	Note : a CSS class ".current" is added to "<li>" elements if neccessary.

== Routing

	If you want to generate nice and clean url, add this route to your config/routes.rb

	map.connect 'posts/date/:year/:month', :controller => :posts, :year => :year, :month => nil, :requirements => {:year => /\d{4}/, :month => /\d{1,2}/}

== Localization

	acts_as_datable uses i18n to display months names in the archive list. Therefore, you will need a date/time format in your localization files : 
	
	fr:
	  date:
	    formats:
	      month_name: "%B"
	  time:
	    formats:
	      month_name: "%B"
	
== Contact

	This plugin has been written by Cédric Bousmanne. 
	You can find contact information on my personnal page : http://cedricbousmanne.com/

acts_as_datable's People

Stargazers

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