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 ? Thanks -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 20 July 2010 20:51, Johann <johann.legaye-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 %> <<<==============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. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Jul 20, 2010 at 15:51, Johann <johann.legaye-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> def show_one_publisher_seven_days > @title = ''foo'' > end...> %script{:type => "text/javascript"} > > var title_text = <% @title %> <<<==============Can you tell us *how* it''s not working, i.e., what it does instead? Are you getting some kind of Javascript error? I don''t know haml yet, but it looks to me like that would probably result in saying: var title_text = foo whereas you want:: var title_text = ''foo''; Try adding the quotes and semicolon and see what happens. If that doesn''t fix it, see if you''re getting a JS error, and if so, tell us what it is. -Dave -- Specialization is for insects. | Professional: http://davearonson.com -Robert Anson Heinlein | Programming: http://codosaur.us -------------------------------+ Leadership: http://dare2xl.com Have Pun, Will Babble! -me | Et Cetera: http://davearonson.net -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 20 July 2010 21:10, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 20 July 2010 20:51, Johann <johann.legaye-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> 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 %> <<<==============> > It is haml not erb. Try > = "var title_text = #{@title}"Oops, quickly returning to add to this after seeing Dave''s response = "var title_text = ''#{@title}''" Colin> > 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. > > Colin >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote:> On 20 July 2010 21:10, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >>> >>> 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 %> � � � <<<==============>> >> It is haml not erb. Try >> = "var title_text = #{@title}" > > Oops, quickly returning to add to this after seeing Dave''s response > = "var title_text = ''#{@title}''"That should be == var title_text = ''#{@title}'' (two equals signs at the beginning and no outer quotes) But this is a terrible idea. What you want to do instead is put the value in a hidden div, then have your JS look at that div. You should never have to generate JS dynamically from Ruby.> > ColinBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 20 July 2010 21:25, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote: >>... >> Oops, quickly returning to add to this after seeing Dave''s response >> = "var title_text = ''#{@title}''" > > That should be > == var title_text = ''#{@title}'' > (two equals signs at the beginning and no outer quotes)Just to clarify this, I think the = "... syntax will work. I have not seen the == syntax previously, it does work, but I cannot see it documented at http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html Am I just missing it there? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks a lot Colin !!! With => = "var title_text = ''#{@title}''" It works perfectly ! On Jul 20, 1:38 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 20 July 2010 21:25, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > Colin Law wrote: > >>... > >> Oops, quickly returning to add to this after seeing Dave''s response > >> = "var title_text = ''#{@title}''" > > > That should be > > == var title_text = ''#{@title}'' > > (two equals signs at the beginning and no outer quotes) > > Just to clarify this, I think the = "... syntax will work. I have not > seen the == syntax previously, it does work, but I cannot see it > documented athttp://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html > > Am I just missing it there? > > Colin-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.