当有人点击静态链接时,是否可以添加Flash通知?
<%= link_to "show clip", sign_up_page_path, notice: "You must sign up or sign in to view clips." %>
事实是,这不是身份验证问题,因为内容是静态的,我只想手动链接到注册页面并发出通知,声明用户必须“注册或登录才能查看剪辑。“
答案 0 :(得分:0)
如果你看rail guides
,就说
The flash is a special part of the session which is cleared with each request. This means that values stored there will only be available in the next request, which is useful for passing error messages etc.
如果你看一下你的link_to语法:
link_to(body, url, html_options = {})
# url is a String; you can use URL helpers like
# posts_path
Is it possible to add a flash notice when someone clicks a static link
答案是不,因为如果您查看link_to语法,那么它就不允许您设置Flash消息
正如@Max Williams
所指出,您可以使用浏览器对话框提醒用户注册,然后将他/她重定向到您的注册页面。您也可以使用bootstraps模式显示您的消息,但我个人认为bootstrap popover
会比模式更好,或者您可以只显示tooltip
要求用户注册或登录