简体   繁体   中英

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

(new to Stack Overflow, please be gentle)

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. (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.

But the error that always shows up when clicking a link is:

Routing Error

No route matches [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

<%= 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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