How to hide from Feed?

There are many ratings, actions and users. Each table has the following row:

t.boolean "conceal", default: false 

When submitting an assessment, this can be done:

 pry(main)> Valuation.find(16) Valuation Load (0.1ms) SELECT "valuations".* FROM "valuations" WHERE "valuations"."id" = ? LIMIT 1 [["id", 16]] => #<Valuation:0x007fbbee41cf60 id: 16, conceal: true, user_id: 1, created_at: Thu, 23 Apr 2015 20:24:09 UTC +00:00, updated_at: Thu, 23 Apr 2015 20:24:09 UTC +00:00, likes: nil, name: "CONCEAL NEW"> 

This prevents another user from seeing this value :name in their profile via @valuations = @user.valuations.publish in users_controller and scope :publish, ->{ where(:conceal => false) } in valuations.rb.

How can we also hide this rating in the action feed? Here is the same rating found as an action:

 Activity.find(24) Activity Load (0.1ms) SELECT "activities".* FROM "activities" WHERE "activities"."id" = ? LIMIT 1 [["id", 24]] => #<Activity:0x007fbbebd26438 id: 24, user_id: 1, action: "create", test: nil, trackable_id: 16, trackable_type: "Valuation", created_at: Thu, 23 Apr 2015 20:24:09 UTC +00:00, updated_at: Thu, 23 Apr 2015 20:24:09 UTC +00:00, conceal: false> 

Do you see how this is a lie here? How can we do this?

 class Activity < ActiveRecord::Base belongs_to :user belongs_to :trackable, polymorphic: true scope :publish, ->{ where(:conceal => false) } end class ActivitiesController < ApplicationController def index @activities = Activity.publish.order("created_at desc").where(user_id: current_user.following_ids) end end 
0
scope ruby ruby-on-rails model-view-controller feed
source share
1 answer

You really don't need a boolean in your Activity model. Just create a getter method that gets the masking value from the score record.

 class Activity < ActiveRecord::Base belongs_to :user belongs_to :trackable, polymorphic: true scope :publish, ->{ where(:conceal => false) } def conceal trackable.conceal end end 
+1
source share

All Articles