【发布时间】:2015-07-24 15:56:30
【问题描述】:
您好,我已生成迁移到 add_column rails g migration AddColumnToEmployees
class AddColumnToEmployees < ActiveRecord::Migration
def change
add_column :employees, :role, "enum('SUPER-ADMIN', 'HR','ADMIN','INVENTORY','EMPLOYEE')", :default => 'EMPLOYEE'
end
end
运行rake db:migrate
现在我想在我的视图中访问角色,我写了这个:
<%=f.select :role, :collection => Employee.roles %>
但它没有访问它。它给出了错误
undefined method 'roles' for #<Class:0xc2acd88>
请指导如何解决这个问题。提前致谢!
【问题讨论】:
-
不应该是
Employee.role吗?我不认为 Rails 的属性是复数的。
标签: ruby-on-rails ruby-on-rails-4 enums