我的用户模型没有 :name
字段,但我想在我的注册表单中包含一个 :name
字段,该字段将用于创建记录after_create
中的另一个模型。
class User < ActiveRecord::Base
after_create :create_thing
private
def create_thing
@thing = Thing.new
@thing.name = <here's where I need help>
@thing.save!
end
end
如何从注册表单中获取姓名?
最佳答案
在您的模型中为名称添加 attr_accessor
attr_accessor :name
这将允许您将它添加到表单并使用它在您的 after_create 中生成正确的数据
关于ruby-on-rails - 使用 Devise in Rails 4 的虚拟属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19081039/