在我的模型中,BookHeader 有很多 Category 所以,当编辑或创建新的 BookHeader 时,表单显示像这样 Enum 修复?
我想通过定义 category_enum 方法将“类别#{id}”更改为类别名称,但它仍然不起作用。请帮忙!
BookHeader 模型的代码
class BookHeader < ActiveRecord::Base
attr_accessible :autho, :category_id, :description, :title, :book_type, :year,:publisher_id,:detail
has_many :books
belongs_to :category
belongs_to :publisher
TYPE = {:ebook=>"Ebook",:paper_book=> "PaperBook",:magazine=> "Magazine",:media=> "Media"}
DEFAULT_TAB = :paper_book
BOOKS_PER_PAGE = 1 # books to show in a pages (pagination)
extend FriendlyId
def book_type_enum #it worked here
TYPE.map{|key, val| [val]}
end
def category_enum #but dont' work here
["a","b"]
end
编辑表单代码
edit do
field :title
field :description, :text do
ckeditor do true end
end
field :autho
field :book_type
field :category
end
请参阅此链接中的 Division 属性