无法批量分配受保护的属性:time_zone

时间:2013-12-23 22:06:47

标签: mysql ruby-on-rails forms activerecord

我在尝试提交simple_form时遇到此错误:

= simple_form_for(@profile, :url => profile_path, :method => :put) do |f|
  = f.error_notification
  .container
    = f.input :time_zone, :collection => ActiveSupport::TimeZone.all, 
      :label_method => :to_s, :value_method => :name, :include_blank => false
  .actions
    = f.button :submit

我已将time_zone放在可访问的属性中:

class Profiles < ActiveRecord::Base
  attr_accessible :time_zone

  belongs_to :user
end

并将列添加到表中:

class AddTimeZoneToProfile < ActiveRecord::Migration
  def change
    add_column :profiles, :time_zone, :string, :default => "UTC"
  end
end

并运行迁移:

$rake db:migrate
==  AddTimeZoneToProfile: migrating ===========================================
-- add_column(:profiles, :time_zone, :string, {:default=>"UTC"})
   -> 0.0369s
==  AddTimeZoneToProfile: migrated (0.0370s) ==================================

由于某种原因,我得到了质量分配错误。这里有什么问题的任何线索?

更新: 这些是随更新请求发送的参数:

{"utf8"=>"✓", "_method"=>"put", "authenticity_token"=>"udKomXmmmOG+7Z4YKR03y9zMg58rnx1EXqE33a+6Shw=", "profile"=>{ "time_zone"=>"Stockholm"}, "commit"=>"Update Profile", "action"=>"update", "controller"=>"profiles"}

谢谢,

1 个答案:

答案 0 :(得分:0)

感谢评论者,我认为我有两个模型文件:profile.rbprofiles.rb,第一个是我应该拥有的,复数文件是错误的。我将attr_accessible添加到第二个。当然它不起作用。

愚蠢的错误总是会产生愚蠢的错误,

感谢。