lundi 29 juin 2015

Rails 4: Request view only access to users records (Self-Referential)

My goal is to give users a way to send requests to share there records with a user with director role and the inverse of director user requesting. So after some investigation, I realized the setup was very similar to how social media platforms send friend requests. However the requests would be one sided for viewing records.

User A wants to share his 'records' with User B who has the managerial type role.

I have concluded this has to do with making a table called 'Requests' at which has states of [pending, accepted]. Maybe another state for sent?

So far I came up with

 rails g model request user:reference status:string

Model Files

 class Request < ActiveRecord::Base
   belongs_to :user
   belongs_to :student, class_name: 'User', foreign_key: 'user_id'
 end


 class User < ActiveRecord::Base
   ...

   has_many :students
   has_many :requests
   has_many :accepted_requests, :class_name => "Request", # conditions doesn't work on rails 4
   has_many :pending_requests, :class_name => "Request" # conditions doesn't work on rails 4

   ...
 end

Ember CLI Model (User)

export default DS.Model.extend({
  requests: DS.hasMany('request')
  students: DS.hasMany('student', {inverse: true});
});

A couple good resources I found but wasn't sure how to implement as one-sided.

Friendship has_many through model with multiple status'

http://ift.tt/PjCZii

Anybody guide me to the next step or missing parts?




Aucun commentaire:

Enregistrer un commentaire