Skip to content Skip to sidebar Skip to footer

In Rails, How Should We Get Parameters In Java Scripts?

When I use the code <%= render 'chart', width:100 %> I can get the width value in the page, like <%= width %> But if I want to get the width value in java script in

Solution 1:

You can directly output the value in the javascript part:

<scripttype="text/javascript">var width = <%= width %>;
</script>

The code in Ruby/Rails will be interpreted during the rendering, and will output the (ruby) variable width inside the generated HTML.

Post a Comment for "In Rails, How Should We Get Parameters In Java Scripts?"