Ezequiel Ramiro Ezequiel Ramiro - 6 days ago 6
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

try

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