ruby on rails - Multiple recipients of activity -


i want use this (public_activity) gem create newsfeed. there recipient_id column, 1 recipient of activity. but, in cases, have multiple recipients (e.g show activity people following specific record) - number of recipients can more 100, lot of separate records create @ once , display.

what best way go doing this?

i found this suggestion, although can't work , lot of errors.

one solution might create custom column

t.text :user_recipients 

store ids of users should activity (because, example, might following specific record). then, check if current_user.id belongs_to set of numbers. set of numbers ("1, 3, 4") first converted array ([1, 3, 4]) , can use array.include?(current_user.id)

is way it?

also, records have empty user_recipients column not shown.

at end, should this:

@activities = publicactivity::activity.where(/records current_user.id belongs user_recipients array/ + /column not empty/) 

when searching inside string there's 4 possibilities

  • id in beginning of field
    ex: "id, 2, 3"
  • id in end of field
    ex: "1, 2, id"
  • id in middle of field
    ex: "1, id, 3"
  • id number in field
    ex "id"

so here's how think query might like

@activities = publicactivity::activity.where(   "user_recipients ':id,%' or     user_recipients '%, :id' or    user_recipients '%, :id,%' or    user_recipients = ':id'", id: current_user.id) 

the reason why can't simple like %id% match partial numbers, meaning id = 5 match [1, 10, 15] though there's no 5, 15 match, need check commas , make sure i'm not picking wrong number.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -