Rails select 使用时出现 AssociationTypeMismatch

a8885313 · November 17, 2012 · Last by a8885313 replied at November 18, 2012 · 2524 hits

Completed 500 Internal Server Error in 3ms

ActiveRecord::AssociationTypeMismatch (Type(#70137863544680) expected, got String(#701 37856381380)): app/controllers/houses_controller.rb:65:in block in update' app/controllers/houses_controller.rb:64:inupdate'

表单是这样写的 <%= f.select :type, @types.collect{|p| [p.name,p.id ]} %>

该问题已解决,但是有个问题想问大家 我有一个“Type”的字符串能不能把它变成类 在 java 中可以 class.forname rails 中有没有提供类似的方法

你找的是不是这个 constantize

Module".constantize  # => Module
"Class".constantize   # => Class

#2 楼 @allenwei 恩,谢谢。解决了

You need to Sign in before reply, if you don't have an account, please Sign up first.