How to pass Ruby variables to a JavaScript function in a Rails view?

前端 未结 6 1549
一个人的身影
一个人的身影 2020-11-28 12:53

I\'m wondering what the best practice is for passing variables to JavaScript functions in a rails view. Right now I\'m doing something like:

<% content_f         


        
6条回答
  •  执笔经年
    2020-11-28 13:31

    - content_for :javascripts_vars do
      = "var costs_data = #{@records[:cost_mode][:data].to_json}".html_safe
      = "var graph_data = #{@records[:cost_mode][:graph].to_json}".html_safe
    

提交回复
热议问题