<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>fatbigbright (胖大海)</title>
    <link>https://ruby-china.org/fatbigbright</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>请教个问题</title>
      <description>&lt;p&gt;环境：rails 3.2.12 + ruby 1.9.3p392
重现步骤：&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;rails g model order number:string description:text quantity:integer&lt;/code&gt;建立一个 model，&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bundle exec rake db:migration&lt;/code&gt;更新数据库&lt;/li&gt;
&lt;li&gt;使用&lt;code&gt;rails c&lt;/code&gt;在控制台中增加一条 order 数据。&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rails g migration add_type_to_order&lt;/code&gt;为 order 表增加一个 type 字段。&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bundle exec rake db:migration&lt;/code&gt;再次更新数据库&lt;/li&gt;
&lt;li&gt;在&lt;code&gt;rails c&lt;/code&gt;的控制台中使用
&lt;code&gt;order = Order.first&lt;/code&gt;
&lt;code&gt;order.type = 'C'&lt;/code&gt;
&lt;code&gt;order.save&lt;/code&gt;
这时发现 order 可以正常更新
继续使用
&lt;code&gt;order.update_attributes( :type =&amp;gt; "M" )&lt;/code&gt;来更新，发现报错“ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: type”，上网查说“type”是个比较敏感的词，于是改成了“order_type”，结果发现仍然不能使用 update_attributes 方法来更新这个字段的值，向各位前辈求教这是为什么呢？先行谢过了～&lt;/li&gt;
&lt;/ol&gt;</description>
      <author>fatbigbright</author>
      <pubDate>Thu, 12 Dec 2013 11:19:46 +0800</pubDate>
      <link>https://ruby-china.org/topics/16157</link>
      <guid>https://ruby-china.org/topics/16157</guid>
    </item>
  </channel>
</rss>
