Answer the question
In order to leave comments, you need to log in
How to get user id in Javascript?
There is a user model and an event. In the
$("#calendar").fullCalendar(
events: '/events.json'
)
script, /evens.json must be preceded by the user id.
path site.com/user/id/events The
question is how to write a script with user id?
Answer the question
In order to leave comments, you need to log in
in views/layouts/application.html.erb write in head
<script>
window.user_id = <%= user_signed_in? && current_user.id %>;
</script>
url = "/users/#{window.user_id}/events.json"
1. Move this script to the view template (html, haml ...) (so that the script does not go to the pipeline once), and insert <%= @user.id %> directly in the code
2. Specify the user ID in some any date attribute:
<div id='calendar'>
<div class='event' data-user-id='<%= user.id %>'>
</div>
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question