0

I try to render hash in my rails application to be considering as object in javascript.

div.sort-cartridges data-cartridges-selections=cartridges_selections

where cartridges_selections is function which return ruby hash.

But if in jQuery + coffee I try to fetch data object I get string:

$ ->
  console.log typeof $('.sort-cartridges').data('cartridges-selections')
  # => string

I tried to do JSON.parse, but it gave error to me. So, what I need to do?

Alex Antonov
  • 14,134
  • 7
  • 65
  • 142

2 Answers2

0

Please try like this in view page.

div.sort-cartridges data: {cartridges-selections: cartridges_selections }
Sanket
  • 490
  • 4
  • 11
  • Have you tried above solution? your solution is also correct, you used rails, I have given slim syntax. – Sanket Jun 24 '14 at 10:09
0

Correct (find by myself):

= content_tag :div, id: 'sort-cartridges', data: { 'cartridges-selections' => cartridges_selections } do
  # my content
Alex Antonov
  • 14,134
  • 7
  • 65
  • 142