Devise 设计:在为(资源)不工作在路径中签名后
我正在使用Desive进行用户注册/登录。但当用户从公共访问页面登录时,应设计重定向到根路径 我试着用这个:Devise 设计:在为(资源)不工作在路径中签名后,devise,ruby-on-rails-3.2,Devise,Ruby On Rails 3.2,我正在使用Desive进行用户注册/登录。但当用户从公共访问页面登录时,应设计重定向到根路径 我试着用这个: def after_sign_in_path_for(resource) request.referrer end 当用户尝试登录时,会出现错误“未正确重定向” 有人能告诉我怎么做吗?我相信如果我是对的,那么当用户登录时,您要做的是覆盖重定向,如果您没有生成designes controllers,则在controllers/designe/sessions\u controller
def after_sign_in_path_for(resource)
request.referrer
end
当用户尝试登录时,会出现错误“未正确重定向”
有人能告诉我怎么做吗?我相信如果我是对的,那么当用户登录时,您要做的是覆盖重定向,如果您没有生成designes controllers,则在
controllers/designe/sessions\u controller.rb中更改以下方法。完成此操作后,您将希望在designe/sessions\u controller.rb中包含以下内容
def create
self.resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
# respond_with resource, :location => after_sign_in_path_for(resource)
if current_user.role? :administrator
redirect_to dashboard_path
else
redirect_to rota_days_path
end
end
在上面的示例中,默认情况下,sessions\u controller-create
方法使用以下内容:\respond\u with resource,:location=>在我已注释掉的(resource)
登录路径之后。通过添加检查当前用户角色是否为管理员的if语句。如果是,则会重定向到仪表板页面。如果没有,则重定向到rota页面
或者,Desive助手声明您也可以执行以下操作:
def after_sign_in_path_for(resource)
stored_location_for(resource) ||
if resource.is_a?(User) && resource.can_publish?
publisher_url
else
super
end
end
希望这有帮助
更新
def create
@hospital_booking = HospitalBooking.new(params[:hospital_booking])
respond_to do |format|
if @hospital_booking.save
format.html { redirect_to :back, notice: 'Photographer Shift was successfully created.' }
format.json { render json: @hospital_booking, status: :created, location: @hospital_booking }
else
format.html { render action: 'new' }
format.json { render json: @hospital_booking.errors, status: :unprocessable_entity }
end
end
end
这里发生的情况是,当保存医院预订时,它会重定向回问题页面,而不是重定向到其他页面。进一步阅读这里:我相信如果我是对的,那么当用户登录时,您要做的是覆盖重定向,如果您没有生成designes控制器,则在controllers/designe/sessions\u controller.rb中更改以下方法。完成此操作后,您将希望在designe/sessions\u controller.rb中包含以下内容
def create
self.resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
# respond_with resource, :location => after_sign_in_path_for(resource)
if current_user.role? :administrator
redirect_to dashboard_path
else
redirect_to rota_days_path
end
end
在上面的示例中,默认情况下,sessions\u controller-create
方法使用以下内容:\respond\u with resource,:location=>在我已注释掉的(resource)
登录路径之后。通过添加检查当前用户角色是否为管理员的if语句。如果是,则会重定向到仪表板页面。如果没有,则重定向到rota页面
或者,Desive助手声明您也可以执行以下操作:
def after_sign_in_path_for(resource)
stored_location_for(resource) ||
if resource.is_a?(User) && resource.can_publish?
publisher_url
else
super
end
end
希望这有帮助
更新
def create
@hospital_booking = HospitalBooking.new(params[:hospital_booking])
respond_to do |format|
if @hospital_booking.save
format.html { redirect_to :back, notice: 'Photographer Shift was successfully created.' }
format.json { render json: @hospital_booking, status: :created, location: @hospital_booking }
else
format.html { render action: 'new' }
format.json { render json: @hospital_booking.errors, status: :unprocessable_entity }
end
end
end
这里发生的情况是,当保存医院预订时,它会重定向回问题页面,而不是重定向到其他页面。进一步阅读此处:什么是发布者url?如果将其替换为“request.referer”,则会出现错误“页面未正确重定向”。如何将用户重定向到后页?@user2206724在(资源)的路径中签名后,您在哪里执行此操作。此外,publisher\u url
只是designe\u helper.rb
显示的示例。我正在定义它的应用程序控制器,如果我用任何其他定义的路径替换request.referer,它就会工作。但是我不想要定义的路径,我想要它重定向到上一页。@user2206724好的,我相信你想要的是重定向到发出请求的页面。在通常情况下,您可以使用redirect\u to:back
example@user2206724请参阅更新并了解发布者的url是什么?如果将其替换为“request.referer”,则会出现错误“页面未正确重定向”。如何将用户重定向到后页?@user2206724在(资源)的路径中签名后,您在哪里执行此操作。此外,publisher\u url
只是designe\u helper.rb
显示的示例。我正在定义它的应用程序控制器,如果我用任何其他定义的路径替换request.referer,它就会工作。但是我不想要定义的路径,我想要它重定向到上一页。@user2206724好的,我相信你想要的是重定向到发出请求的页面。在通常情况下,您可以使用redirect\u to:back
example@user2206724请参阅更新并阅读