我们偶尔会向潜在客户发送定制的注册链接。该链接包含可用于预填写注册表的参数。
http://www.example.com/users/sign_up?user[company_name]=Foo&user[region]=NA
我们的注册表包含接受公司名称和地区的字段。可以根据注册链接预先填写。
这在实践中应该有效,但这并不是因为registrations#new
行动已实施。这new https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb#L6行动称为build_resource
具有空哈希的方法。
def new
resource = build_resource({})
respond_with resource
end
The 构建资源 https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb#L85方法忽略了resource_params
当输入非零时。
def build_resource(hash=nil)
hash ||= resource_params || {}
self.resource = resource_class.new_with_session(hash, session)
end
我不得不超越new
我的注册控制器中的操作来解决这个问题。我不喜欢我的解决方案,因为它很脆弱。
def new
resource = build_resource
respond_with resource
end
有没有理由new
使用空哈希调用操作?是否可以在没有空哈希的情况下调用它(就像在create
行动)?