Ruby array to Javascript array

Let’s assume you are using erb. A first approach:

<%= javascript_tag "account_ids = #{account_ids.to_json.html_safe};" %>

The problem is that this creates a global variable without context (who uses it?). That’s why I’d rather call a function defined somewhere in your JS code:

<%= javascript_tag "setAccounts(#{account_ids.to_json.html_safe});" %>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)