【问题标题】:How should I protect mass-assignment in Sinatra app with Datamapper?我应该如何使用 Datamapper 保护 Sinatra 应用程序中的批量分配?
【发布时间】:2013-04-24 15:34:43
【问题描述】:

我在 Sinatra 应用中有 Link 模型

class Link
  include DataMapper::Resource
  has n, :views

  validates_presence_of :url,
    message: "You must specify a URL."
  validates_length_of   :url,
    maximum: 4096,
    allow_blank: true,
    message: "That URL is too long."
  validates_format_of :url,
    with: %r{^(https?|ftp)://.+}i,
    allow_blank: true,
    message: "The URL must start with http://, https://, or ftp:// ."

  property :id,         Serial
  property :url,        String
  property :token,      String
  property :created_at, DateTime
end

如何设置attr_accessible :url, :token之类的东西?

【问题讨论】:

标签: ruby sinatra mass-assignment ruby-datamapper attr-accessible


【解决方案1】:

您可以使用 gem dm-rails 中的 DataMapper::MassAssignmentSecurity 模块。

class Link

  include DataMapper::Resource
  include DataMapper::MassAssignmentSecurity
  attr_accessible :url, :token

  # ...

end

【讨论】:

    猜你喜欢
    • 2012-04-08
    • 2012-01-14
    • 1970-01-01
    • 1970-01-01
    • 2017-11-29
    • 2021-05-17
    • 1970-01-01
    • 2011-10-23
    • 2017-11-05
    相关资源
    最近更新 更多