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/pages ?
Thank you
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.