fullCalendar jquery users id

297 views Asked by At

Im trying to implement a Medic Online Date System with a fullCalendar on ruby on rails. (College Project) need help please.

So the real question is this. If i have 2 medics, example Alex and Alfred and Alex User_id = 1 and Alfred User_id = 2. If Alex is logged in my Medic Online System as User_id 1, fullCalendar will show only User_id = 1 appointments and not all of the medics appointments, and viceverse with Alfred, if im logged in with Alfred's account fullCalendar then will show me only Alfred's appointments.

Note: All my database is fully functionally with users_id but i have NO CLUE how to validate this id to show different medics appointments and not all the medic appointments.

Thanks!

1

There are 1 answers

3
rkamun1 On BEST ANSWER

When you log in store the user_id in a session:

session[:user_id]=user.id

in your application controller

class ApplicationController < ...
  def current_user
    @current_user ||= session[:user_id] && User.find_by_id(session[:user_id]) # Use find_by_id to get nil instead of an error if user doesn't exist
  end
  helper_method :current_user #make this method available in views
end

Now you can user current_user in your views or controllers

Use the ID to filter out the events. Check out the CanCanCan gem, or if this is as simple as it gets then do

def index
 @events = current_user.events #display these
end