简体   繁体   English

路由错误 - 没有路由匹配外部URL的[GET]

[英]Routing Error - No route matches [GET] for an external URL

(new to Stack Overflow, please be gentle) (Stack Overflow新增,请温柔)

In my Rails app, which is much like Reddit, I'd like a user to be able to click on the link posted and... actually go to that link. 在我的Rails应用程序中,它非常像Reddit,我希望用户能够点击发布的链接并...实际上转到该链接。 (They'd be going to other websites, as you'd expect.) For instance, if someone posted a title with a link going to www.google.com , someone should be able to click on the title text and, you know, go to Google. (他们会去其他网站,正如您所期望的那样。)例如,如果有人发布了一个带有链接到www.google.com的标题,那么有人应该可以点击标题文本,你知道,去谷歌。

But the error that always shows up when clicking a link is: 但是,单击链接时始终显示的错误是:

Routing Error 路由错误

No route matches [GET] "/links/www.google.com" 没有路线匹配[GET]“/links/www.google.com”

(EDIT) Here is my relevant part of the Show page: (编辑)这是我显示页面的相关部分:

<div class="page-header">
<h1><a href="<%= @link.url %>"><%= @link.title %></a><br>            
<small>Submitted by <%= @link.user.email %></small></h1>
</div>

<%= image_tag @link.image.url(:medium) %>
<br>
<br>
<div class="btn-group">
<%= link_to 'Visit URL', @link.url, class: "btn btn-primary" %>
</div>

<% if @link.user == current_user %>
<div class="btn-group">
    <%= link_to 'Edit', edit_link_path(@link), class: "btn btn-default" %>
    <%= link_to 'Destroy', @link, method: :delete, data: { confirm:  'Are you sure?' }, class: "btn btn-default" %>
</div>
<% end %>`

Does anyone know why that might be? 有谁知道为什么会这样? And how to fix the issue? 以及如何解决这个问题?

It is hard for me to see the exact problem without you posting a little more information like the view for the page you are talking about, but in rails it assumes most links are relative so you are going to want it to be have the protocol on the link ie 'http://' or 'https://', so something like 我很难看到确切的问题,如果你没有发布更多的信息,比如你正在谈论的页面的视图,但在rails中它假设大多数链接是相对的,所以你会希望它有协议链接即'http://'或'https://',所以类似于

<%= link_to 'Title', 'http://www.url.com' %> . <%= link_to 'Title', 'http://www.url.com' %>

How you go about implementing that in your application really depends and I'd have to have more code to figure out but I hope this helped. 你如何在你的应用程序中实现它真的取决于我必须有更多的代码来解决,但我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM