6
可能使用没有导轨的ActiveModel ?. 是否可以在桌面应用程序中使用ActiveModel?没有导轨的ActiveModel
可能使用没有导轨的ActiveModel ?. 是否可以在桌面应用程序中使用ActiveModel?没有导轨的ActiveModel
随着Rails 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