开发者

Rails - Injected a snippet of HTML in any page when some parameter is met?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜