4

我只是想了解 Rails 的一部分,特别是 access_attributes

请参见下面的示例:

irb(main):001:0> Ec2TypeSpecification.accessible_attributes
=> #<ActiveModel::MassAssignmentSecurity::WhiteList: {"", "api_name", "api_size", "api_type", "cores", "core_type", "compute_units", "ebs_optimization", "ephemeral_drives", "io_performance", "max_ips", "memory", "name", "support_32_bit", "support_64_bit", "total_ephemeral_storage"}>

为什么是空字符串?它有什么作用?或者,我的模型有什么问题吗?

gem 'rails', '3.2.13'

编辑:添加模型

这就是整个模型(我的项目不是很远)

class Ec2TypeSpecification < ActiveRecord::Base
  attr_accessible :api_name, :api_size, :api_type, :cores, :core_type, :compute_units, :ebs_optimization, 
    :ephemeral_drives, :io_performance, :max_ips, :memory, :name, :support_32_bit, :support_64_bit, 
    :total_ephemeral_storage 
end
4

1 回答 1

3

It represents the default :

attr_accessible nil 

A blank whitelist is a wide-open whitelist, so this default just requires you to specify the other params you want to mass assign as attr_accessible. Instead of a blank whitelist, it's a whitelist containing nil.

# nil.to_s  = ""
于 2013-04-27T21:53:05.013 回答