Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Alfred provides better attr_accessor handling on your application.
tag: v1.0.1

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.gitignore
.rspec
.travis.yml
Gemfile
README.textile
Rakefile
alfred.gemspec

README.textile

Alfred – the unobtrusive butler who takes care of the uninvited guests

Alfred provides better attr_accessor handling on your application.

Contact

Documentation

Preview

Without Alfred, and with much mess:

# app/models/user.rb
class User < ActiveRecord::Base
  attr_accessible :email, :password, :password_confirmation
  attr_accessible :email, :password, :password_confirmation, :username, as: :admin
  attr_accessible :email, :password, :password_confirmation, :username, as: :on_create
end

Have to use a special role:

# app/controllers/users_controlelr.rb
class UsersController < ApplicationController
  def create
    @user = User.create(params[:user], as: :on_create)
  end
end

With Alfred and no hassles:

# app/models/user.rb
class User < ActiveRecord::Base
  alfred_accessible :email, :password
  alfred_accessible :username, as: :admin
  alfred_accessible :username, on: :create
end

Nothing special here:

# app/controllers/users_controlelr.rb
class UsersController < ApplicationController
  def create
    @user = User.create(params[:user])
  end
end

Usage

alfred_accessible and alfred_protected behaves just like attr_accessible and attr_protected on steroids.

accessible and protected

  class User < ActiveRecord::Base
    alfred_accessible :a, :b
    alfred_protected :c, :d
  end

roles

Custom inherits from default role:

  class User < ActiveRecord::Base
    alfred_accessible :a, :b
    alfred_accessible :c, :d, as: :custom
  end

custom inheritance

  class User < ActiveRecord::Base
    alfred_accessible :a, :b
    alfred_accessible :c, :d, as: :custom
    alfred_accessible :e, :f, as: :custom2, inherit: :custom
  end

events

  class User < ActiveRecord::Base
    alfred_accessible :a, :b
    alfred_accessible :c, :d, on: :create
    alfred_accessible :e, :f, on: :update
  end

passwords

password_confirmation will automatically added by default.

  class User < ActiveRecord::Base
    alfred_accessible :password
  end

Requirements

  • Ruby 1.9.2 (Ruby 1.9.1 is not supported).
  • Rails 3.1.x (Rails 3.0.x is not supported).
Something went wrong with that request. Please try again.