0

I am getting from controller data in global variable @controller_data which contains array.

I am also using Highcharts, where is used following procedure for rendering data in charts:

data = [{
           y: 55.11,
           color: colors[0]
         }, {
           y: 21.63,
           color: colors[1]
         }, {
           y: 11.94,
           color: colors[2]
         }, {
           y: 7.15,
           color: colors[3]
         }, {
           y: 2.14,
           color: colors[4]
         }];

I am using HAML template system. How to fill out this Javascript array with data from controller?

Thanks

1 Answer 1

1

Assuming that @controller_data is just a simple array of hashes, suitable for passing directly to JavaScript:

:javascript
  data = #{@controller_data.to_json};

Haml allows you to do string interpolation inside of content, including JavaScript Filters.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you @Phrogz, but I would need to prepare exactly the same array as is in the example above, .to_json doesn't prepare it that way.
@user984621 If you want more help, you need to provide the data of your @controller_data. For example, what does @controller_data.inspect produce?

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.