Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spangenberg/alfred
Alfred provides better attr_accessor handling on your application.
https://github.com/spangenberg/alfred
Last synced: about 1 month ago
JSON representation
Alfred provides better attr_accessor handling on your application.
- Host: GitHub
- URL: https://github.com/spangenberg/alfred
- Owner: spangenberg
- Created: 2011-08-11T23:20:43.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2014-07-03T16:03:48.000Z (over 10 years ago)
- Last Synced: 2024-03-15T07:04:54.106Z (10 months ago)
- Language: Ruby
- Homepage: http://rubygems.org/gems/alfred
- Size: 148 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.textile
Awesome Lists containing this project
README
h1. Alfred - the unobtrusive butler who takes care of the uninvited guests "!https://secure.travis-ci.org/parcydo/alfred.png?branch=master!":http://travis-ci.org/parcydo/alfred
Alfred provides better attr_accessor handling on your application.
h2. Contact
* "Github":http://github.com/parcydo
* "Twitter":http://twitter.com/parcydoh2. Documentation
* "Wiki":http://github.com/parcydo/alfred/wiki
* "YARD":http://rdoc.info/github/parcydo/alfredh2. Preview
h3. 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
endHave to use a special role:
# app/controllers/users_controlelr.rb
class UsersController < ApplicationController
def create
@user = User.create(params[:user], as: :on_create)
end
endh3. 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
endNothing special here:
# app/controllers/users_controlelr.rb
class UsersController < ApplicationController
def create
@user = User.create(params[:user])
end
endh2. Usage
alfred_accessible and alfred_protected behaves just like attr_accessible and attr_protected on steroids.
h3. accessible and protected
class User < ActiveRecord::Base
alfred_accessible :a, :b
alfred_protected :c, :d
endh3. roles
Custom inherits from default role:
class User < ActiveRecord::Base
alfred_accessible :a, :b
alfred_accessible :c, :d, as: :custom
endh3. custom inheritance
class User < ActiveRecord::Base
alfred_accessible :a, :b
alfred_accessible :c, :d, as: :custom
alfred_accessible :e, :f, as: :custom2, inherit: :custom
endh3. events
class User < ActiveRecord::Base
alfred_accessible :a, :b
alfred_accessible :c, :d, on: :create
alfred_accessible :e, :f, on: :update
endh3. passwords
password_confirmation will automatically added by default.
class User < ActiveRecord::Base
alfred_accessible :password
endh2. Requirements
* Ruby 1.9.2 (Ruby 1.9.1 is not supported).
* Rails 3.1.x (Rails 3.0.x is not supported).