Hi all, Can I have a ruby code inside a java script function written in .js file? When I tried it, i got an error. e.g. consider following function inside myscript.js file myscript.js function sayHi { <%name="xyz"%>; alert(''HI <%=name%>''); } But this works if I have above function in a rhtml file inside <script> tag. Any inputs in this regard will be really helpful. Thanks and Regards, Medha. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
no, you cannot have ruby code inside a standalone js file, as it is your browser that requests the file directly from the webserver. it is NOT being parsed/interpreted/executed on the server. when you put the ruby code into the rhtml template within <script> tags then that code IS being parsed as part of the template file. Chris On 1/2/07, Medha Kulkarni <medhak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Hi all, > > Can I have a ruby code inside a java script function written in .js file? > When I tried it, i got an error. > e.g. consider following function inside myscript.js file > > myscript.js > function sayHi > { > <%name="xyz"%>; > alert(''HI <%=name%>''); > } > > But this works if I have above function in a rhtml file inside <script> tag. > > Any inputs in this regard will be really helpful. > > Thanks and Regards, > Medha. > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 2, 2007, at 10:26 AM, Medha Kulkarni wrote:> Can I have a ruby code inside a java script function written in .js > file?Yes and no. You can''t have Ruby code within a .js file stored in the public directory, but you could generate a javascript file from a controller (this will require some disabling any layouts, etc.). Your HTML will probably need to reference the generated javascript "file" directly, rather than through Rails'' helper function. -faisal --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 02 Jan 2007, at 18:06, Faisal N Jawdat wrote:>> Can I have a ruby code inside a java script function written >> in .js file?http://www.danwebb.net/2006/11/24/minusmor-released Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Medha Kulkarni wrote:> Hi all, > > Can I have a ruby code inside a java script function written in .js > file? > When I tried it, i got an error. > e.g. consider following function inside myscript.js file > > myscript.js > function sayHi > { > <%name="xyz"%>; > alert(''HI <%=name%>''); > } > > But this works if I have above function in a rhtml file inside <script> > tag. > > Any inputs in this regard will be really helpful. > > Thanks and Regards, > Medha.You can''t embed ruby in a static js file (just as you can''t in a static HTML file). You *can* put it in an *r*js file, just as you can in an *r*html file. add an action called myscript, a view called myscript.rjs and put a script tag into your rhtml file with src = /controller/myscript Alan -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---