I need to check Rails running environment type in a js file such as application.js. I can check that like " if RAILS_ENV == ''development'' ..." in a .rb/.rhtml/.rjs,but I need to do the detection in a pure javascript file. I try these first (append to application.js): function appEnv(env) { var current_env = ''''; var scripts = $$(''script[src="applications.js"]''); if(scripts.first()) { current_env = ''production''; } else { current_env = ''development''; } return (env ? current_env == env.toLowerCase() : current_env ); } then I use it as: if(appEnv(''development'')) { // do sth } or if(appEnv() == ''production'' ) { // do sth } but when I change the server running under production type.I found the scripts'' src still output with a time stamp string like : <script src="/javascripts/application.js?1184146500" type="text/ javascript"></script> not my expect as: <script src="/javascripts/application.js" type="text/javascript"></ script> I don''t want to put sth in the layout files like: <script>var current_env = ''''<%= RAILS_ENV -%>'';</script> because I have many layout files, that would be a hell if have to change each one . I have an idea is to cover the "javascript_path" helper, to add some attribute make it return as: <script src="/javascripts/application.js?1184146500" type="text/ javascript" env="development"></script> Then I could check that tag with js. But I don''t how to . Any suggestion? -RainChen --~--~---------~--~----~------------~-------~--~----~ 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 Wed, 2007-07-11 at 03:00 -0700, RainChen wrote:> I need to check Rails running environment type in a js file such as > application.js. > I can check that like " if RAILS_ENV == ''development'' ..." in > a .rb/.rhtml/.rjs,but I need to do the detection in a pure javascript > file. > > I try these first (append to application.js): > function appEnv(env) > { > var current_env = ''''; > var scripts = $$(''script[src="applications.js"]''); > if(scripts.first()) > { > > current_env = ''production''; > } > else > { > current_env = ''development''; > } > return (env ? current_env == env.toLowerCase() : current_env ); > } > > then I use it as: > if(appEnv(''development'')) > { > // do sth > } > > or > > if(appEnv() == ''production'' ) > { > // do sth > } > > but when I change the server running under production type.I found the > scripts'' src still output with a time stamp string like : > <script src="/javascripts/application.js?1184146500" type="text/ > javascript"></script> > > not my expect as: > <script src="/javascripts/application.js" type="text/javascript"></ > script> > > I don''t want to put sth in the layout files like: > <script>var current_env = ''''<%= RAILS_ENV -%>'';</script> > > because I have many layout files, that would be a hell if have to > change each one . > > I have an idea is to cover the "javascript_path" helper, to add some > attribute make it return as: > <script src="/javascripts/application.js?1184146500" type="text/ > javascript" env="development"></script> > > Then I could check that tag with js. > But I don''t how to . > > Any suggestion?You can do javascript_include_tag(''application'', :class => RAILS_ENV) I''m pretty sure "env" is not a valid attribute for script tags, but that only matters if you''re a purist. -- Tore Darell <toredarell-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I dont what to modify each layout file.Is there a better way? On Jul 11, 6:38 pm, Tore Darell <toredar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Wed, 2007-07-11 at 03:00 -0700, RainChen wrote: > > I need to check Rails running environment type in a js file such as > > application.js. > > I can check that like " if RAILS_ENV == ''development'' ..." in > > a .rb/.rhtml/.rjs,but I need to do the detection in a pure javascript > > file. > > > I try these first (append to application.js): > > function appEnv(env) > > { > > var current_env = ''''; > > var scripts = $$(''script[src="applications.js"]''); > > if(scripts.first()) > > { > > > current_env = ''production''; > > } > > else > > { > > current_env = ''development''; > > } > > return (env ? current_env == env.toLowerCase() : current_env ); > > } > > > then I use it as: > > if(appEnv(''development'')) > > { > > // do sth > > } > > > or > > > if(appEnv() == ''production'' ) > > { > > // do sth > > } > > > but when I change the server running under production type.I found the > > scripts'' src still output with a time stamp string like : > > <script src="/javascripts/application.js?1184146500" type="text/ > > javascript"></script> > > > not my expect as: > > <script src="/javascripts/application.js" type="text/javascript"></ > > script> > > > I don''t want to put sth in the layout files like: > > <script>var current_env = ''''<%= RAILS_ENV -%>'';</script> > > > because I have many layout files, that would be a hell if have to > > change each one . > > > I have an idea is to cover the "javascript_path" helper, to add some > > attribute make it return as: > > <script src="/javascripts/application.js?1184146500" type="text/ > > javascript" env="development"></script> > > > Then I could check that tag with js. > > But I don''t how to . > > > Any suggestion? > > You can do javascript_include_tag(''application'', :class => RAILS_ENV) > > I''m pretty sure "env" is not a valid attribute for script tags, but that > only matters if you''re a purist. > > -- > Tore Darell <toredar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---