【问题标题】:unnecessary characters getting added in URL when using rails link_to helper anchor tag使用 rails link_to helper 锚标记时在 URL 中添加了不必要的字符
【发布时间】:2016-10-26 07:13:06
【问题描述】:

我正在尝试将#xyz 添加到使用rails link_to 助手生成的链接中。

以下是我的代码:

<%= link_to('', edit_notification_path(:id => item.id,:type =>"requester_template", 
:notification_type => @notification_type,:anchor => "#xyz"), 
:class => 'icon-pencil-3' ) %>

但是生成的 URL 看起来像

email_notifications/3/edit/requester_template?notification_type=ticket#%23es

即有一个额外的 %23 与锚点一起添加。

我在这里做错了什么? (这里是 Rails 初学者)

【问题讨论】:

    标签: ruby-on-rails link-to


    【解决方案1】:

    您必须将 :anchor =&gt; "#xyz" 更改为 :anchor =&gt; "xyz"。选项:anchor 已包含#

    【讨论】:

      【解决方案2】:

      试试这个

      <%= link_to('', edit_notification_path(id: item.id,type: "requester_template", 
      notification_type: @notification_type,anchor: "xyz"), 
      class: 'icon-pencil-3' ) %>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-24
        • 1970-01-01
        相关资源
        最近更新 更多