【发布时间】:2023-03-25 08:05:01
【问题描述】:
当您尝试自定义其行为时,我无法理解设计的工作原理。
我有两种不同的模型需要处理:Society 和 Collaborator,并且它们的注册表必须在相同的视图中。
所以我必须重写“设计注册控制器创建方法”,编写一个新的控制器来处理这两个模型。
痛苦来了。
从这里“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
结束
我不知道如何在不影响守望者功能的情况下使其工作。 (构建资源)。有什么建议吗?我找不到任何不使用 STI 的解决方案!
【问题讨论】:
标签: ruby-on-rails controller devise helper