gpt4 book ai didi

ruby-on-rails - 获取运行时错误 : "In order to use #url_for, you must include routing helpers explicitly" when I've already included them

转载 作者:数据小太阳 更新时间:2023-10-29 07:55:03 24 4
gpt4 key购买 nike

在 Controller 中,当已经登录的用户偶然发现注册页面时,我尝试运行这段代码

def index
if current_user
redirect_to homebase_url #should provide url to home for logged in users
end
end

我已经完成了 Rails 错误消息所说的并添加了:include Rails.application.routes.url_helpers 到包含的 Controller 类。虽然仍然收到此错误。绝对不想出于遗留目的将 URL 硬编码到那里。谢谢

最佳答案

删除 include Rails.application.routes.url_helpers 声明,不需要它,除非它在类似 helper 的东西中。默认情况下,路由包含在 Controller 中。将它包含在模型或 Controller /初始化器中(路由在初始化器之前加载)违反 MVC 架构,可能会导致不需要的行为。

关于ruby-on-rails - 获取运行时错误 : "In order to use #url_for, you must include routing helpers explicitly" when I've already included them,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41903124/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com