Ruby on rails 如何将重定向_更改为带有自定义控制器的设备?
我使用Desive和自定义控制器(用户控制器)。与其登录并转到Ruby on rails 如何将重定向_更改为带有自定义控制器的设备?,ruby-on-rails,ruby,devise,ruby-on-rails-6,Ruby On Rails,Ruby,Devise,Ruby On Rails 6,我使用Desive和自定义控制器(用户控制器)。与其登录并转到user/edit,我更喜欢服务于主页。为此,我需要编辑designe会话create controller方法 我知道我可以按照Deave提供的说明编辑Deave自定义控制器: # before_action :configure_sign_in_params, only: [:create] # GET /resource/sign_in # def new # super # end # POST
user/edit
,我更喜欢服务于主页。为此,我需要编辑designe会话create controller方法
我知道我可以按照Deave提供的说明编辑Deave自定义控制器:
# before_action :configure_sign_in_params, only: [:create]
# GET /resource/sign_in
# def new
# super
# end
# POST /resource/sign_in
# def create
# super
# end
# DELETE /resource/sign_out
# def destroy
# super
# end
# protected
# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_in_params
# devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
# end
那么按照这些说明,我如何让create
方法准确地执行它当前的操作,但将\u重定向到“/”
而不是它当前正在执行的操作
注意:这是它目前正在做的事情:
self.resource = resource_class.new(sign_in_params)
clean_up_passwords(resource)
yield resource if block_given?
respond_with(resource, serialize_options(resource))
另外请注意,我可以直接从github上的Desive复制该代码,然后对其进行编辑,如下所示:
self.resource = resource_class.new(sign_in_params)
clean_up_passwords(resource)
yield resource if block_given?
redirect to: "/"
但是我想使用
super
方法来实现这一点,因为这是Deave说明中推荐的方法。无需重新定义创建
操作,因为Deave允许您在方法的路径中签名后使用
def after_sign_in_path_for(resource)
root_path
end
无需重新定义create
action,因为designe允许您在
方法的路径中对进行签名后使用action
def after_sign_in_path_for(resource)
root_path
end
你试过设计助手吗?你试过设计助手吗?