开发者

Allowing a Post to show datetime without user input (Ruby on Rails)

I want to be able to show a datetime stamp ( I want it to appear like - "Posted 5 days ago" ), but i dont want the date field to appear when an user is making a post.

I just want to post to add it automatically. Any help? (Im just learning Rails so its all new to m开发者_运维技巧e...)

Thanks in advance.


For a Forum Application I did this:

<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, "/users/#{forum.most_recent_post.last_poster_id}" %>
    <% else %> no posts <% end %>
</td>

Here <%= distance_of_time_in_words_to_now forum.most_recent_post.last_post_at %> ago by "username" so, you may try this. I think that can work in this scenario too. Just use distance_of_time_in_words_to_now post.time here post.time is the time when user made a post.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜