2012-02-23 51 views
0

我有以下代码:在rails中使用link_to和post.title?

<% @posts.each do |post| %> 
    <h2>Title: <%= post.title %></h2> 
    <p>Author: <%= post.user.username %></p> 
    <p>Created At: <%= post.created_at %></p> 
    <p>Content: <%= post.content %></p> 
    <p>Votes: <%= post.total_votes %></p> 
    <p>Comments: <%= post.comments_count %></p> 
    <ul> 
     <li><%= link_to 'Show', post %></li> 
     <li><%= link_to 'Edit', edit_post_path(post) %></li> 
     <li><%= link_to 'Destroy', post, confirm: 'Are you sure?', method: :delete %></li> 
    </ul> 

我想有这样的事情:

<h2><%= link_to "post.title" %></h2> 

什么是这样做的正确方法吗?

回答

10

<h2><%= link_to post.title, post %></h2>

1

如果你想用你能做到<h2><%= link_to "Title : #{post.title}", post %></h2>太VAR添加文本。