D
D
Damir Nurgaliev2015-05-23 10:31:16
JavaScript
Damir Nurgaliev, 2015-05-23 10:31:16

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

3 answer(s)
R
Renat Ibragimov, 2015-05-24
@damirik

in views/layouts/application.html.erb write in head

<script>
window.user_id = <%= user_signed_in? && current_user.id %>;
</script>

and in your coffeescript
url = "/users/#{window.user_id}/events.json"

V
Viktor Vsk, 2015-05-23
@viktorvsk

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>

3. Get the user's ID http request for some condition

K
kkrieger, 2015-05-23
@kkrieger

Look at the article on habré habrahabr.ru/post/138994 the gon gem is called

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question