Hi all,
I want to create charts in my website. I want to fill them with
variables. So in my controller, I put the variables I want to use :
class ChartsController < ApplicationController
def show_one_publisher_seven_days
@title = 'foo'
end
end
And in my view (show_one_publisher_seven_days.haml), I want to assign
my javascript variable with the variable I created in my controller.
%script{:type => "text/javascript"}
var title_text = <% @title %> <<<===============
%p This is the chart for one publisher for the last seven days
%div{:id => "7days_one_publisher", :style => "width: 800px; height:
400px; margin: 0 auto"}
but it doesn't work... Do you know how to do that ?
It is haml not erb. Try
= "var title_text = #{@title}"
Check the html generated in the browser to check it is what you expect.
By the way, it is generally considered bad form to put javascript like
this in the view. Ideally all javascript should be in separate files.