简体   繁体   English

link_to在本地工作,但在Heroku上不工作

[英]link_to works local, but doesn't work on Heroku

I have a portfolio application built with Ruby 2.3.0 and Rails 5.0.0 that has links to external urls that work locally but do not work when deployed to Heroku. 我有一个使用Ruby 2.3.0和Rails 5.0.0构建的投资组合应用程序,该应用程序具有指向外部URL的链接,这些URL在本地可以工作,但是在部署到Heroku时不起作用。

<%= link_to image_tag(project.index_image), project.url %>

There are two different types of links that are not working and producing different symptoms. 有两种不同类型的链接不起作用,并产生不同的症状。

External Application Links 外部应用程序链接
In production the links to my other applications successfully redirect to the desired urls but the url's do not update in the browser to the new page. 在生产中,指向我其他应用程序的链接已成功重定向到所需的URL,但是该URL在浏览器中不会更新到新页面。

Github links Github链接
The links to github do not work and redirect to a blank screen. 指向github的链接不起作用,并重定向到黑屏。 That screen displays the following error in the developer console: 该屏幕在开发人员控制台中显示以下错误:

Refused to display 'https://github.com/my_repo' in a frame because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'none'".

Try to creating a helper class for custom URL like below 尝试为自定义URL创建一个帮助程序类,如下所示

On the helpers/application_helper.rb helpers/application_helper.rb

def custom_link(image, url)
    link_to image_tag(image), "#{url}"
end

And the view look like this 看起来像这样

<%= custom_link project.index_image, project.url %>

This should work I hope because it's working my own. 我希望这应该可行,因为它是我自己的。

Hope it helps 希望能帮助到你

You can try the following: 您可以尝试以下方法:

<%= link_to project.url do %>
  image_tag(project.index_image)
<% end %>

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

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