mysql - 无法批量分配 protected 属性 : time_zone

标签 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"}

谢谢

最佳答案

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

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

谢谢。

关于mysql - 无法批量分配 protected 属性 : time_zone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20751873/

相关文章:

php - UPDATE MySQL 有时只能工作。不是每次

javascript - 普通按钮上的 onclick 正在提交表单

PHP 更新 MySQL 数据库表

php - 会计年度更改时自动重置发票编号

mysql - 合并 SQL 条目

javascript - Rails JavaScript 开发 : debug vs releases

ruby-on-rails - Rails — 带有 "dot"的参数(例如/google.com)

Mysql 加入重复项

ruby-on-rails - 如何动态地向 ROAR 代表添加属性?

javascript - 在 Javascript 中禁用文本字段自动对焦