我刚刚开始学习 rails 和 ruby,所以如果这太愚蠢,请多多包涵。
我的应用程序中有几种不同的 AppModule 类型,它们的行为不同但数据相似,因此我使用单表继承来保存它们。
但是,当尝试允许用户明确选择他们想要的类型时,app_modules/new.html.erb
我会收到警告WARNING: Can't mass-assign these protected attributes: type
。以下是相关代码:
<% form_for(@app_module) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :type %><br />
<%= f.select( :type, options_from_collection_for_select(AppModule.subclasses().map{ |c| c.name}, 'to_s', 'to_s')) %>
</p>
<%= f.submit 'Create' %>
<% end %>
我已经尝试attr_accessible :type
在模型文件中进行显式设置,但它不起作用
我正在使用 rails 2.3.8 和 ruby 1.8.7。
任何帮助都非常感谢,谢谢...