如何检查current_user是否喜欢这个?

时间:2012-12-22 13:15:57

标签: ruby-on-rails ruby-on-rails-3

我正在使用rails3,devise和acts_as_votable

我准备了视图,根据他的投票情况显示'书签'或'取消书签' 但我不知道该放什么。有人有想法吗?

<% if xxxxxxxxxxxx %> <= *when @community hasn't been voted by current_user*              
  <%= link_to t('.bookmark', :default => t("helpers.links.bookmark")),
              bookmark_community_path(@community), :class => 'btn' %>
<% else %>
  <%= link_to t('.unbookmark', :default => t("helpers.links.unbookmark")),
              bookmark_community_path(@community), :class => 'btn-danger' %>
<% end %>

1 个答案:

答案 0 :(得分:1)

你可以尝试

current_user.voted_for? @community

更新:文档https://github.com/ryanto/acts_as_votable#the-voter

中的示例
@user.likes @comment1

@user.voted_for? @comment1 # => true