Ezequiel Ramiro Ezequiel Ramiro - 11 months ago 56
Ruby Question

How can I pass my current_user.id to AngularJs Controller

I'm getting my current_user.id from Ruby on Rails and trying to pass it to my angular controller through HTML hidden input>

<input type="hidden" ng-model="user_id" value="<%= current_user.id%>"></input>


Debugging, my scope is undefined for "$scope.user_id", and I need this value to send it to my server.

Am I doing something wrong? Is there a better way?

Answer Source

try

<input type="hidden" 
       ng-model="user_id" 
       ng-init="user_id = <%= current_user.id%>"></input>