How can I get rails to process and serve application.js.erb instead of application.js? I want to mix Ruby and Javascript code in the file. I am building Javascript arrays from data that i keep in a Rails model and the arrays are static. -- 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.
Vladimir Rybas
2010-Apr-17 11:44 UTC
Re: Question: How do I mix Ruby and Javascript in application.js
Create application.js.erb and put it in views/js/ then you render :partial => ''js/application.js.erb'', :locals => {:data => @your_data} and use variable ''data'' in your partial like <script> var foo = <%= data[:foo]%> </script> On Sat, Apr 17, 2010 at 2:13 AM, Jose <jolohaga-BUHhN+a2lJ4@public.gmane.org> wrote:> How can I get rails to process and serve application.js.erb instead of > application.js? > > I want to mix Ruby and Javascript code in the file. I am building > Javascript arrays from data that i keep in a Rails model and the > arrays are static. > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.