【问题标题】:ActiveModel without rails没有导轨的 ActiveModel
【发布时间】:2010-12-06 01:43:52
【问题描述】:

是否可以在没有导轨的情况下使用 ActiveModel? 是否可以在桌面应用程序中使用 ActiveModel?

【问题讨论】:

    标签: ruby-on-rails ruby activemodel


    【解决方案1】:

    有了 Rails 3,你可以!查看this post on Rubyinside.com

    【讨论】:

      【解决方案2】:

      是的,例如使用验证:

      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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-18
        • 2022-01-08
        • 2016-08-20
        相关资源
        最近更新 更多