I am trying to insert the data that I defined in my controller, in my opinion. 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 look at the generated html file, it looks like
<script>
some_var = ["hi", "bye"]
some_ints = [1,2,3,4]
</script>
those. ints are fine, but all the quotes slipped away. I tried
some_var = <%= @var_data.map {|i| i.html_safe} %>
but it did nothing (and also html_safe did not work on the whole array). How should I do it?
thank
source
share