当您尝试定制其行为时,我在理解设计如何工作时遇到麻烦。设计仅适用于STI机型吗?
我有两个不同的模式来处理:学会和合作者,并在报名表必须在他们两个同样的观点。
因此,我必须通过编写处理两种模型的新控制器来覆盖“设计注册控制器创建方法”。
这里来的痛苦。
从这里“Devise form within a different controller”和here,我知道我有定义这些新的帮手,使设计作品:
module ContentHelper
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
end
而创造的方法,我想重写是这样的:
def create
build_resource
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_with resource
end
结束
我不知道如何使它的工作原理没有妥协的监督功能。 (build_resource)。任何建议?我找不到任何解决方案没有STI使用!