
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
This plugin provides a workflow for approving new records and changes to existing records.
Add the gem to your Gemfile:
gem 'acts-as-approvable'
Then run the generator:
rails g acts_as_approvable
Add the gem to config/environment.rb
config.gem 'acts-as-approvable'
Then run rake gems:install
. After the gem is installed, run the generator:
$ script/generate acts_as_approvable
These options are also available by passing --help
as an option to the generator.
--base BASE Base class for ApprovableController.
--haml* Generate HAML views instead of ERB.
--owner [User] Enable and, optionally, set the model for approval ownerships.
--scripts Copy javascripts for ApprovalsController and its views.
* This option is not available in Rails 3. You should configure your template engine in config/application.rb
API Documentation is available online.
The generator creates an initializor at config/initializers/acts_as_approvable.rb
. A sample
initializer might look like this:
ActsAsApprovable.view_language = 'haml'
ActsAsApprovable::Ownership.configure
The Ownership
functionality expects a User
model in your project by default, but by providing
an :owner
option you can change the expected model to whatever you wish. .configure
also
accepts a block which it applies to the Approval
model, allowing you to override methods as
you see fit.
For example, to only allow Users with the "admin" role to 'own' an Approval, change your initializer to something like this:
ActsAsApprovable.view_language = 'haml'
ActsAsApprovable::Ownership.configure do
def self.available_owners
owner_class.all(:conditions => ['role', 'admin'])
end
end
Require approval for new Users, but not modifications...
class User < ActiveRecord::Base
acts_as_approvable :on => :create, :state_field => :state
# Let the user know they've been approved
def after_approve(approval)
ApprovalMailer.deliver_user_approved(self.email)
end
# Let the user know they were rejected
def after_reject(approval)
ApprovalMailer.deliver_user_rejected(self.email, approval.reason)
end
end
Require approval when a Game's title or description is changed, but not when view or installation count is changed...
class Game < ActiveRecord::Base
acts_as_approvable :on => :update, :ignore => [:views, :installs]
end
Require approval for all changes, except the standard ignored fields (created_at
, updated_at
and :state_field
)...
class Advertisement < ActiveRecord::Base
acts_as_approvable :state_field => :state
end
The following options may be used to configure the workflow on a per-model basis:
:on
The type of events (:create
or :update
) to require approval on.:ignore
A list of fields to ignore for :update
approvals.:only
A list of fields that should be approved. All other fields are
ignored. If set, the :ignore
option is... ignored.:state_field
A local model field to save the :create
approvals state. Useful
for selecting approved models without joining the approvals table.The fields :created_at
, :updated_at
and whatever is set for the :state_field
are automatically ignored.
FAQs
Unknown package
We found that acts-as-approvable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.