In laravel I am use to having
<a href="/chapters/<%= chapter.id%>" data-user-id="<%= @current_user.id %>"> Enroll </a>
If you're going to access any instance variable in a view, you need to define it first (either in a controller or in the view).
Depending on how you have auth set up, you probably have a
current_user method somewhere.
It could be defined in ApplicationController (which has functionality shared by all controllers);
class ApplicationController < ActionController::Base def current_user User.find_by id: session["current_user_id"] # or whatever end helper_method :current_user end
helper_method line makes it accessible in your views, so you can write
<%= current_user.id %>.
You could also write some code so that the
@current_user instance variable is available in all your views:
class ApplicationController < ActionController::Base before_action :define_current_user def define_current_user @current_user = current_user # call the 'current_user' method defined elsewhere end end