0

Im just starting with RoR. I've been following a 10m guide on how to make a blog (link). Here's my problem, code from one of the views

<% @posts.each do |post| %>
<h2><% link_to post.title, post %></h2>
<p>
  <% time_ago_in_words post.created_at %> ago
</p>
<p>
  <% truncate post.text %>
</p>
<% end %>

Post was created using scaffold with title and text being both text. It looks like nothing is getting retrieved from database, neither title, nor text. This is how the page looks in browser (with 2 posts added to the db):
Welcome to my blog
ago
ago

Not sure what could be the cause of this. Using

1 Answer 1

2

Use <%= not <%. It means you cast the value to string and put it into html. With <% you just do some stuff.

<% @posts.each do |post| %>
  <h2><%= link_to post.title, post %></h2>

  <p>
    <%= time_ago_in_words post.created_at %> ago
  </p>

  <p>
    <%= truncate post.text %>
  </p>
<% end %>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Yeah I figured it was something painfully obvious. Learning RoR one mistake at a time :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.