2017-04-03 3 views
0

Ich schreibe einen Blog-Post auf einem Postgres db mit Ruby on Rails. Der Inhalt des Posts in der Tabelle enthält einige externe Links. Ich habe die link_to-Methode verwendet, aber bis jetzt hat dies nur den genauen Code im Browser aus der html.erb-Datei gedruckt. Bisher habe ich versucht:How to link_to aus dem Inhalt der Datenbank in einer html.erb-Seite

<%= link_to 'London Coffee Festival', http://www.londoncoffestival.com %>

<% link_to 'London Coffee Festival', http://www.londoncoffestival.com %>

<%= link_to 'http://www.londoncoffestival.com'do %>London Coffee Festival<% end %>

Aber keine dieser Varianten zu funktionieren scheint ...

meine html.erb Seite:

<%= render "partials/mainnav" %> 
<div class="ui fluid image"><%= image_tag "header_img_thin.jpg" %> 
</div> 
<div class="ui grid container"><!--Main page container--> 
    <div class="row"> 
    <div class="twelve wide column"><!--left Column--> 
     <h1><%= @article.title %></h1> 
<p><%= @article.text %></p> 

<h2>Comments</h2> 
<% @article.comments.each do |comment| %> 
<p><strong>Name</strong> 
<%= comment.commenter %> 
</p> 

<p> 
<strong>Comment:</strong> 
<%= comment.body %> 
</p> 
<% end %> 

<h2>Add a comment:</h2> 
<%= form_for([@article, @article.comments.build]) do |f| %> 
    <p> 
<%= f.label :Name %><br> 
<%= f.text_field :commenter %> 
</p> 
<p> 
<%= f.label :Comment %><br> 
<%= f.text_area :body %> 
</p> 
<p> 
<%= f.submit %> 
</p> 
<% end %> 
<%= link_to 'Back', articles_path %> 


</div><!--end left column--> 
<div class="four wide column"><!--right column--> 
    <p> 
    Text 
    </p> 
    </div><!--end right column--> 
    </div> 
</div><!--End of main page container--> 

enter image description here

Antwort

0

Ein Link in Artikel sollte HTML sein, nicht Ruby. So sollte es

<a href='http://www.londoncoffestival.com'>London Coffee Festival</a> 

und Code ändern in Ihrer Vorlage

<%== @article.text %> 

== ist hier wichtig, wird es Schienen sagen, nicht html in Text

+0

Leider nicht zu entkommen. Was keinen Sinn ergibt. –

+0

@SimonCooper Sind Sie sicher, dass Sie 'erb' verwenden? Denn ich kopiere einfach den exakt gleichen Code oben und es funktioniert –

+0

Yeah def, Dateiname ist 'app/views/articles/show.html.erb'. Ich versuche das nur auf dem lokalen Host. Zurzeit kann nicht in die Produktion gepostet werden. –