Home > Projects | Ruby > ValidAttributes

ValidAttributes

  • 2009-05-20 (水) 12:47
  • hatena button
  • hatena count
  • save this page del.icio.us

Introduction

特定のアトリビュートだけ(または特定のアトリビュート以外)にバリデーションを実行するためのプラグインです。

Installation

ruby script/plugin install git://github.com/kusakari/valid_attributes.git

Example

@foo= Foo.new
if @foo.valid_attributes?(:attr1)
end

if @foo.valid_attributes?(:only => [:attr1, :attr2])
end

if @foo.valid_attributes?(:except => [:attr3, :attr4])
end

if @foo.save_with_valid_attributes(:only => [:attr1, :attr2])
end

if @foo.save_with_valid_attributes(:except => [:attr3, :attr4])
end

begin
  @foo.save_with_valid_attributes!(:only => [:attr1, :attr2])
rescue ActiveRecord::RecordInvalid => e
  # validation error
end

Home > Projects | Ruby > ValidAttributes

Calendar
« 2010 年 9月 »
M T W T F S S
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      
ページ
ブログパーツ

Return to page top