Reputation: 2089
I'm trying to embed data I have defined in my controller in my view. in view.html.erb:
<script>
some_var = <%= @var_data %>
some_ints = <%= @int_data %>
</script>
in my controller:
@var_data = ['hi', 'bye']
@int_data = [1,2,3,4]
however, when I view the generated html file, it looks like
<script>
some_var = ["hi", "bye"]
some_ints = [1,2,3,4]
</script>
ie the ints are fine but all the quotes got escaped. I tried
some_var = <%= @var_data.map {|i| i.html_safe} %>
instead but it didn't do anything (and also html_safe didn't work on the whole array). How should I do this?
Thanks
Upvotes: 3
Views: 1298