Ezequiel Ramiro Ezequiel Ramiro - 1 year ago 74
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


<input type="hidden" 
       ng-init="user_id = <%= current_user.id%>"></input>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download