【发布时间】:2014-02-08 12:02:03
【问题描述】:
Rails 4.1 提供了可用的枚举。我检查了它,它似乎在 Rails 控制台中运行良好。当我尝试通过控制器将数据从视图持久保存到数据库时,出现以下错误
“注册”不是有效的流类型
下面是我的课
class Stream < ActiveRecord::Base
enum stream_type: { sales: 1, registration: 2, student: 3 }
belongs_to :course_presentation
has_many :subscriptions
has_many :contacts, :through => :subscriptions
validates :course_presentation_id, :stream_type, presence: true
end
下面是我用来保存的代码
@stream = Stream.new(stream_params)
def stream_params
params.require(:stream).permit(:stream_type, :course_presentation_id, :is_active, :created_by_user_id, :updated_by_user_id)
end
下面是查看代码
<%= f.label :stream_type %><br>
<%= f.collection_select :stream_type, StreamType.order(:name), :name, :name, include_blank: "<-- select -->" %>
有什么想法吗?我只是无法让它工作
【问题讨论】:
-
你能显示你在发布什么吗?
-
你在哪里定义
StreamType?
标签: ruby-on-rails enums ruby-on-rails-4