English 中文(简体)
从通过复杂的协会归还的记录中删除目前的用户活动
原标题:Eliminating current_user activity from records being returned through a complex association

我已就铁路应用问题(第2.3.9号)建造了一条“Rub”,使用户能够跟踪工程情况。 在开展工作之后,其他用户可以就这项工作发表意见。 我现在正在编制<代码>Dash板指数,以显示最近的活动。

在这一节中,我试图从大家那里就以下各项工作发表评论:<条码>目前——用户已经发表了评论。 我正在成功地将这些意见拉开,命令它们,并通过以下法典限制产出。

我现在试图从目前的用户中删除的评论意见。 该守则是:

页: 1

  <% unless current_user.comment_stream.blank? %>
      <h3>Recent Comments from WODs you commented on</h3>
        <% current_user.comment_stream[0,10].each do |comment| %>
          <p>
             Comment from <%= link_to (comment.user.username), comment.user %> 
             <%= time_ago_in_words(comment.created_at) %> ago on Workout: 
             <%= link_to (comment.workout.title), comment.workout %>
          </p>
        <% end %>
  <% end %>

User.rb

  def workouts_on_which_i_commented
    comments.map{|x|x.workout}.uniq
  end

  def comment_stream
   workouts_on_which_i_commented.map do |w|
     w.comments
   end.flatten.sort{|x,y| y.created_at <=> x.created_at}
  end

<<>Example of Problem:

这里是该法典发生情况的一个例子:

用户A生成一份工作说明和用户B对此的评论意见。 然后,用户C和用户D也就用户A的工作范围发表了意见。 在用户B的仪表板看来,我希望他看到C用户和D用户在活动流程中的意见......但我不希望他看到自己的评论。

我只能使用<代码><%,除非评论.user_id ==当值_user.id %>,但可评估显示的记录数量,因为这些记录是在排他线之前捕鱼的。

问题回答

在评论——流中,你可以补充过滤你发表的评论意见

def comment_stream
  workouts_on_which_i_commented.map do |w|
    w.comments
  end.flatten.reject{|c| c.user_id == current_user.id}.sort{|x,y| y.created_at <=> x.created_at}
end




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签