0.0
No commit activity in last 3 years
No release in over 3 years
Adds the class method "resource_has" (for building dependencies) when included by a controller that inherits from InheritedResources::Base
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

resource_has

============ Build resource dependencies in controllers that inherit from InheritedResources::Base

Usage


class Something < ActiveRecord::Base
  has_one :image
  has_many :users
end
class SomeThingsController < InheritedResource::Base

  resource_has :image, :only => %w(edit update) # resource.build_image on edit and update (defaults to edit only)
  resource_has 3, :users # 3.times.do resource.users.build on edit
  resource_has 3, :users, do |user|
    user.build_dependency # build a dependency of user
    user.name = 'Default'
  end
  resource_has :at_least, 3, :users, { :increments_of => 2 } # will build 3 times if there are no existing users
                                                             # that relate, twice otherwise
  resource_has :at_most, 3, :users # will only build up to 3 users (i.e. if 3 users already exist as relations, no 
                                   # more will be built)
end
Parameters:
  [ OPTIONAL ] Symbol  Modifier (:at_least | :at_most), at least will ensure that there are at least this 
                       many of the relation class, at most will ensure a maximum 
                       of quantifier relation classes)
  [ OPTIONAL ] Integer Quantifier (i.e. how many to build)
  [ REQUIRED ] Symbol  Relation Name (i.e. :images)
  [ OPTIONAL ] Hash    Options ( :increment_by, :only || :on 

Why?

I always found myself writing a protected method called build_dependencies and calling it as a before_filter when using Web app theme for Admin sections