I have an angular module where I set a few strings. I'd also like to set an array of strings in the template as well.
application.html.erb
<script type="text/javascript">
angular.module('userFromServer', [])
.service('currentUser', function() {
<% if logged_in %>
this.name = '<%= @User.name %>';
this.friends = '<%= @User.profile.friends_by_uuid %>';
<% end %>
})
</script>
controller
def friends_by_uuid
self.friends.map{|x| "puser_#{x.uuid}"} # also tried adding .to_json
end
However the output appears to have some escaping issues.
"["puser_589b07ee-b8f1-4214-941d-0ce0b7a6703b", "puser_ec7d2918-d514-4c42-91fc-641ed2958fcd"]"
var desired_output = "["puser_589b07ee-b8f1-4214-941d-0ce0b7a6703b", "puser_ec7d2918-d514-4c42-91fc-641ed2958fcd"]
How can I render an array of strings in a rails template?