首页 > 解决方案 > 有没有办法在控制器内使用 link_to 标签?

问题描述

我想在控制器中使用 link_to 标记。我添加了include ActionView::Helpers::UrlHelper,这是我的代码。

def authenticate_user!
    unless user_signed_in?
        flash[:danger] ="You must sign in or sign up first!#{link_to("test", root_path) }".html_safe
        redirect_to new_session_path
    end
end

如果我去浏览器,它显示You must sign in or sign up first!<a href="/">test</a>

您知道如何正确显示此消息吗?(我的意思是没有标签)

谢谢!

标签: ruby-on-railsrubylink-to

解决方案


推荐阅读