In my app I have projects.
Whenever a project_id is present in the PARAMS I would like to inject the following:
<script>
project_id = 123123;
</script>
Any suggestions on how to do this without having to touch multiple views/pag开发者_如何学编程es ?
Thank you
Put it in the layout, that way it can show up on all your pages:
# application.html.erb ... <% if !params[:project_id].blank? %> <script> project_id = <%= params[:project_id] %>; </script> <% end %> ...
Better yet, if you have a common _javascript partial that gets loaded in all of your layouts, put your code in that partial.
精彩评论