Movatterモバイル変換


[0]ホーム

URL:


Skip to ContentSkip to Search
Ruby on Rails 8.1.1

Class ActiveModel::Error<Object

v8.1.1

Active Model Error

Represents one single error

Methods
A
D
F
M
N
S

Constants

CALLBACKS_OPTIONS=[:if, :unless, :on, :allow_nil, :allow_blank, :strict]
 
MESSAGE_OPTIONS=[:message]
 

Attributes

[R]attribute

The attribute ofbase which the error belongs to

[R]base

The object which the error belongs to

[R]options

The options provided when callingerrors#add

[R]raw_type

The raw value provided as the second parameter when callingerrors#add

[R]type

The type of error, defaults to:invalid unless specified

Class Public methods

new(base, attribute, type = :invalid, **options)Link

Source:show |on GitHub

# File activemodel/lib/active_model/error.rb, line 102definitialize(base,attribute,type =:invalid,**options)@base =base@attribute =attribute@raw_type =type@type =type||:invalid@options =optionsend

Instance Public methods

detail()Link

Alias for:details

details()Link

Returns the error details.

error =ActiveModel::Error.new(person,:name,:too_short,count:5)error.details# => { error: :too_short, count: 5 }
Also aliased as:detail

Source:show |on GitHub

# File activemodel/lib/active_model/error.rb, line 148defdetails  {error:raw_type }.merge(options.except(*CALLBACKS_OPTIONS+MESSAGE_OPTIONS))end

full_message()Link

Returns the full error message.

error =ActiveModel::Error.new(person,:name,:too_short,count:5)error.full_message# => "Name is too short (minimum is 5 characters)"

Source:show |on GitHub

# File activemodel/lib/active_model/error.rb, line 158deffull_messageself.class.full_message(attribute,message,@base)end

match?(attribute, type = nil, **options)Link

See if error matches providedattribute,type, andoptions.

Omitted params are not checked for a match.

Source:show |on GitHub

# File activemodel/lib/active_model/error.rb, line 165defmatch?(attribute,type =nil,**options)if@attribute!=attribute|| (type&&@type!=type)returnfalseendoptions.eachdo|key,value|if@options[key]!=valuereturnfalseendendtrueend

message()Link

Returns the error message.

error =ActiveModel::Error.new(person,:name,:too_short,count:5)error.message# => "is too short (minimum is 5 characters)"

Source:show |on GitHub

# File activemodel/lib/active_model/error.rb, line 134defmessagecaseraw_typewhenSymbolself.class.generate_message(attribute,raw_type,@base,options.except(*CALLBACKS_OPTIONS))elseraw_typeendend

strict_match?(attribute, type, **options)Link

See if error matches providedattribute,type, andoptions exactly.

All params must be equal to Error’s own attributes to be considered a strict match.

Source:show |on GitHub

# File activemodel/lib/active_model/error.rb, line 183defstrict_match?(attribute,type,**options)returnfalseunlessmatch?(attribute,type)options==@options.except(*CALLBACKS_OPTIONS+MESSAGE_OPTIONS)end

Instance Protected methods

attributes_for_hash()Link

Source:show |on GitHub

# File activemodel/lib/active_model/error.rb, line 203defattributes_for_hash  [@base,@attribute,@raw_type,@options.except(*CALLBACKS_OPTIONS)]end

[8]ページ先頭

©2009-2025 Movatter.jp