6
레일이없는 ActiveModel을 사용할 수 있습니까?. 데스크톱 응용 프로그램에서 ActiveModel을 사용할 수 있습니까?레일이없는 ActiveModel
레일이없는 ActiveModel을 사용할 수 있습니까?. 데스크톱 응용 프로그램에서 ActiveModel을 사용할 수 있습니까?레일이없는 ActiveModel
레일 3을 사용하면됩니다! 유효성 검증을 사용하여 예를 들어, 예 this post on Rubyinside.com
를 체크 아웃 :
require 'active_model'
class Cat
include ActiveModel::Validations
attr_accessor :id, :name
validates_presence_of :name
puts "meow!"
end
테스트를 클래스에서 위 :
$ irb -r ./cat.rb
meow!
irb(main):002:0> cat = Cat.new
=> #<Cat:0xb99e44>
irb(main):003:0> cat.valid?
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
=> false
irb(main):004:0> cat.name = "puss"
=> "puss"
irb(main):005:0> cat.valid?
=> true