type
列に単一テーブルの継承を持つモデルがあります。
class Pet < ActiveRecord::Base
TYPES = [Dog, Cat, Hamster]
validates_presence_of :name
end
<select>
新規ページと編集ページにドロップダウンを提供したい:
<% form_for @model do |f| %>
<%= f.label :name %>
<%= f.text_input :name %>
<%= f.label :type %>
<%= f.select :type, Pet::TYPES.map { |t| [t.human_name, t.to_s] } %>
<% end %>
それは私に次のエラーを与えます:
ActionView::TemplateError (wrong argument type String (expected Module))
Rubyは予約#type
語を#class
. 両方試してみました
class Pet < ActiveRecord::Base
...
alias_attribute :klass, :type
end
と
class Pet < ActiveRecord::Base
...
def klass
self.type
end
def klass=(k)
self.type = k
end
end
どちらも機能しませんでした。助言がありますか?奇妙なことに、私のマシン (RVM 上の MRI 1.8.6) では正常に動作しますが、ステージング サーバー (RVM ではなく MRI 1.8.7) では失敗します。