0
我希望能够显示日期时间戳(我希望它看起来像 - “5天前发布”),但我不想日期字段在用户发布帖子时出现。允许帖子显示没有用户输入的日期时间(Ruby on Rails)
我只想发布自动添加。任何帮助? (我只是学习Rails,所以它对我来说都是新的...)
在此先感谢。
我希望能够显示日期时间戳(我希望它看起来像 - “5天前发布”),但我不想日期字段在用户发布帖子时出现。允许帖子显示没有用户输入的日期时间(Ruby on Rails)
我只想发布自动添加。任何帮助? (我只是学习Rails,所以它对我来说都是新的...)
在此先感谢。
对于论坛申请我这样做:
<td class="right">
<% if forum.most_recent_post %><%= distance_of_time_in_words_to_now forum.most_recent_post.last_post_at %> ago by <%= link_to forum.most_recent_post.user.login, "https://stackoverflow.com/users/#{forum.most_recent_post.last_poster_id}" %>
<% else %> no posts <% end %>
</td>
这里<%= distance_of_time_in_words_to_now forum.most_recent_post.last_post_at %>
前的“用户名”,因此,您可以尝试这个。我认为这也可以在这种情况下工作。只需在这里使用distance_of_time_in_words_to_now post.time
post.time是用户发布帖子的时间。
嗨我试过的代码,但它说,我有一个未定义的方法“distance_of_time_in_word_to_now”任何帮助? – ChrisBedoya 2011-03-27 20:18:59
Nvm。我最终添加了这个:<%= link_to“#{distance_of_time_in_words_to_now(post.created_at)} ago”,post%>,它工作的很完美!... – ChrisBedoya 2011-03-27 20:31:15
@ChrisBedoya - 在我的情况下,上面的代码工作,所以我粘贴那个:P,好吧,如果它按照你在评论中提到的方式工作,欢呼...... :) – Surya 2011-03-28 06:05:49