Acts As Scoped Rails Plugin

Posted by acts_as_flinn Thu, 19 Jul 2007 16:15:00 GMT

I’m pleased to announce the public availability of the acts_as_scoped plugin.

From the README:

This plugin wraps find in a scope based on a persistent variable. This enables you to use something like the userstamp plugin to ensure a model’s find method returns objects scoped within the current user.

Documentation

http://saas.rubyforge.org/acts_as_scoped

Rubyforge Project

http://rubyforge.org/projects/saas

Usage


# You'll need to add a user_id column to the sandwiches table

class Sandwich < ActiveRecord::Base
  acts_as_scoped :user # belongs_to is included
end

class User < ActiveRecord::Base
  cattr_accessor :current
  has_many :sandwiches
end

class ApplicationController < ActionController::Base 
...
  before_filter :current_user

  def current_user
    User.current = User.find(session[:user_id]) unless session[:user_id].blank?
  end
...

Installation

script/plugin install svn://rubyforge.org/var/svn/saas/acts_as_scoped/trunk/acts_as_scoped


Software as a Service

The plugin is part of the Software as a Service project on Rubyforge. You can use this plugin in conjunction with something similar to the userstamp plugin to automagically limit the scope of your find, calculate, save, delete methods. It is used with other plugins as a drop in that will allow you to turn just about any rails application into a software as a service.

Trackbacks

Use the following link to trackback from your own site:
http://www.actsasflinn.com/trackbacks?article_id=acts-as-scoped&day=19&month=07&year=2007


ss_blog_claim=746d258dc975cb7923cc57154dbf1d71