1

I have the following in a html.erb file:

<%= @location_list = [['test',2]] %>
<script type="text/javascript">
 var test = <%= @location_list.to_json %>
 alert(test);
</script>

And the alert is not showing up.

However if I do <%= @location_list = [[3,2]] %> - The alert is showing up.

Why?

2
  • Are there any JS errors in the console? Commented Mar 20, 2012 at 0:26
  • Kyle. Doing @location_list.to_json.html_safe did the trick, but I don't know why. Commented Mar 20, 2012 at 5:06

1 Answer 1

1

<%= %> tag means output something. In your case, you probably dont want to output anything, so I guess you are looking for <% @location_list = [['test',2]] %>, which means normal statement no output will be involved

Sorry, havn't really answer your question.

var test = <%= @location_list.to_json %>

should be

var test = "<%=j @location_list.to_json %>"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.