0
I Use This!
Activity Not Available

Project Summary

Please note that this project has moved to Github: http://github.com/avdgaag/acts_as_publishable*

Specify this act if you want to show or hide your object based on date/time settings. This act lets you specify two dates two form a range in which the model is publicly available; it is unavailable outside it.

InstallationUse subversion to check out this plugin into your Rails project:

svn checkout http://actsaspublishable.googlecode.com/svn/trunk/ actsaspublishableYou can also check out or export stable releases; see http://actsaspublishable.googlecode.com/svn/tags/.

UsageYou can add this behaviour to your model like so:

class Post < ActiveRecord::Base
acts_as_publishable
endThen you can use it as follows:

post = Post.create(:title => 'Hello world')
post.published? # => true

post.publish!
post.published? # => true

post.unpublish!
post.published? # => falseYou can use two special finder methods to find the published or unpublished objects. Use them like you use your standard #find:

Post.find(:all).size # => 15
Post.find_published(:all).size # => 10
Post.find_unpublished(:all).size # => 5Finally, there are scoping methods for limiting your own custom finders to just published or unpublished objects. These are simple wrapper methods for the #with_scope method and hence are used as follows:

class Post < ActiveRecord::Base
def find_recent
published_only do
find :all, :limit => 5, :order => 'created_at DESC'
end
end
endDo note that it is considered poor style to use scoping methods like this in your controller. You can, but always try moving it into you model.

Configuration optionsRight now this plugin has only one configuration option. Models with no publication dates are by default published, not unpublished. If you want to hide your model when it has no explicit publication date set, you can turn off this behaviour with the publish_by_default (defaults to true) option like so:

class Post < ActiveRecord::Base
acts_as_publishable :publish_by_default => false
endDatabase SchemaThe model that you're publishing needs to have two special date attributes:

publish_at unpublish_at These attributes have no further requirements or required validations; they just need to be datetime-columns.

You can use a migration like this to add these columns to your model:

class AddPublicationDatesToPosts < ActiveRecord::Migration
def self.up
add_column :posts, :publish_at, :datetime
add_column :posts, :unpublish_at, :datetime
end

def self.down
remove_column :posts, :publish_at
remove_column :posts, :unpublish_at
end
end

Tags

acts_as plugin publishing rails ruby

In a Nutshell, actsaspublishable...

 No code available to analyze

Open Hub computes statistics on FOSS projects by examining source code and commit history in source code management systems. This project has no code locations, and so Open Hub cannot perform this analysis

Is this project's source code hosted in a publicly available repository? Do you know the URL? If you do, click the button below and tell us so that Open Hub can generate statistics! It's fast and easy - try it and see!

Add a code location

MIT License
Permitted

Sub-License

Private Use

Commercial Use

Modify

Distribute

Forbidden

Hold Liable

Required

Include Copyright

Include License

These details are provided for information only. No information here is legal advice and should not be used as such.

All Licenses

This Project has No vulnerabilities Reported Against it

Did You Know...

  • ...
    Black Duck offers a free trial so you can discover if there are open source vulnerabilities in your code
  • ...
    data presented on the Open Hub is available through our API
  • ...
    there are over 3,000 projects on the Open Hub with security vulnerabilities reported against them
  • ...
    check out hot projects on the Open Hub

 No code available to analyze

Open Hub computes statistics on FOSS projects by examining source code and commit history in source code management systems. This project has no code locations, and so Open Hub cannot perform this analysis

Is this project's source code hosted in a publicly available repository? Do you know the URL? If you do, click the button below and tell us so that Open Hub can generate statistics! It's fast and easy - try it and see!

Add a code location

Community Rating

Be the first to rate this project
Click to add your rating
   Spinner
Review this Project!
Sample ohloh analysis