【问题标题】:Adding an External link in flash notice rails controller在 Flash Notice Rails 控制器中添加外部链接
【发布时间】:2018-04-21 06:08:55
【问题描述】:

我知道这很简单,但我需要将外部链接添加到 Rails 控制器 Flash 通知。现在我有这个

redirect_to root_path, flash[:success] = "Complete this quick survey. <a href='#{'http://google.com'}'>Click here</a>".html_safe

我不断收到错误

TypeError (no implicit conversion of Symbol into String):

正确的语法是什么?

我正在使用 ruby​​ 2.2.1p85 和 Rails 4.0.10

【问题讨论】:

    标签: html ruby-on-rails controller


    【解决方案1】:

    尝试不使用插值。它会起作用。

    redirect_to root_path, flash[:success] = "Complete this quick survey. <a href='https://www.google.com'>Click here</a>".html_safe
    

    或者如果你想插值:

    url = "https://www.google.com"
    redirect_to root_path, flash[:success] = "Complete this quick survey. <a href='#{url}'>Click here</a>".html_safe
    

    【讨论】:

    • 我正在使用 ruby​​ 2.2.1p85 & Rails 4.0.10
    猜你喜欢
    • 1970-01-01
    • 2011-02-11
    • 2011-01-01
    • 1970-01-01
    • 2011-06-20
    • 1970-01-01
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多