到目前为止,我还没有找到任何有效的方法,可以通过使用acts_as_votablegem的upvotes订购问题.
这是我的upvote和索引方法:
def upvote
@question = Question.find params[:id]
@question.liked_by current_user
redirect_to comment_questions_path
end
def index
@comment = Comment.find params[:comment_id]
@questions = @comment.questions
end
Run Code Online (Sandbox Code Playgroud)
我的问题观点:
<%= div_for(question) do %>
<% if question.votes.size > 0 %>
<div class="verifiedanswer">
<%= question.body %>
</div>
<% else %>
<div class="answercontainer2">
<%= question.body %>
</div>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我应该在视图和控制器中放置什么才能使其工作?
Heroku突然停止工作并给了我这个错误:
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
Precompiling assets failed.
Run Code Online (Sandbox Code Playgroud)
经过一些研究,我跑了这条线:
running RAILS_ENV=production bundle exec rake assets:precompile
Run Code Online (Sandbox Code Playgroud)
这工作但现在当我推送更新到heroku时,新的css不会加载.此行以前从未用过:
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment
Run Code Online (Sandbox Code Playgroud)
如果可能,您还可以解释为什么资产:预编译行解决了我原来的问题?
突然之间,我的链接现在变成了黑盒子,同时被徘徊,点击后变成灰色.我不记得改变任何可能导致这种情况的事情.而不是发布我的1300行css有没有人知道为什么会发生这种情况?
我正在使用public_activity gem为用户创建通知列表.使用这篇文章作为参考我试图保持用户没有阅读的通知的计数.当用户点击查看他们拥有的通知时,我希望计数返回到零.上面问题的解决方案是创建一个类方法,如下所示:
def self.unread
where(:read => false)
end
Run Code Online (Sandbox Code Playgroud)
然后把它放在视图中:
user.notifications.unread.update_all(:read => true)
Run Code Online (Sandbox Code Playgroud)
我的控制器看起来像这样:
def notifications
@activities = PublicActivity::Activity.order("created_at desc").where(recipient_id: current_user.id)
end
def self.unread
where(:read => false)
end
Run Code Online (Sandbox Code Playgroud)
我的观点看起来像这样:
<% @activities.each do |activity| %>
<%= render_activity activity %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我的问题是我在哪里添加:
.update_all(:read => true)
Run Code Online (Sandbox Code Playgroud)
在视图中,我如何获得unread.count.