我有附件和類別模型,因此當用戶上傳文件時,他們可以爲該附件選擇一個類別。我希望類別現在是靜態的。有關如何創建靜態類別模型選項的建議? 我現在有這個權利,但我得到了以下錯誤:undefined method 'title' for Syllabus":String
Rails模型常量
類別型號
class Category < ActiveRecord::Base
CATEGORY = ['Syllabus', 'Assignments', 'Handouts', 'Lectures', 'Other']
has_many :attachments
end
附件new.html.erb
<%= simple_form_for([@group, @group.attachments.build]) do |f| %>
<%= f.collection_select :category_id, Category::CATEGORY, :id, :title, { promt: "Choose a Category" } %>
<%= f.submit %>
<% end %>
附件模型
class Attachment < ActiveRecord::Base
belongs_to :user
belongs_to :group
belongs_to :category
end
模式
create_table "categories", force: :cascade do |t|
t.string "title"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "attachments", force: :cascade do |t|
t.string "title"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.string "name"
t.integer "group_id"
t.integer "category_id"
end