简体   繁体   English

Rails 3中的外部引荐来源网址-来自嵌入式脚本标记吗?

[英]External Referrer URL in Rails 3 - from embedded script tag?

I seem to be having a lot of trouble getting a URL referer for an external URL. 我似乎在获取外部URL的URL引用方面遇到很多麻烦。

My app runs through a script people include on their site: 我的应用程序通过人们在其网站上包含的脚本运行:

Like so- 像这样

<script src="http://0.0.0.0:3000/load.js?upid=10b829af3eef17eb203667f5db56ef930eca062fde4a523b" type="text/javascript"></script>

When the page is hit and the script loads, its just matched to a controller action, where the upid is used to look up a record. 当页面被点击并加载脚本时,它刚好与控制器动作匹配,在控制器动作中使用upid查找记录。

That action looks like such: 该动作如下所示:

  def remote
    @page = Page.find_by_upid(params[:upid])
    respond_to do |format|
      format.js
    end    
  end

I'm trying to now see the referring URL, as I want to see where that script tag was embedded. 我现在想查看引用网址,因为我想查看该脚本标记的嵌入位置。

I have tried the following with 0 luck: 我已经尝试了以下0点好运:

    logger.debug "r test: #{request.env['HTTP_REFERER']}"
    logger.debug "r test: #{request.referer}"
    logger.debug "r test: #{request.original_url}"

They all either return blank, or this URL http://0.0.0.0:3000/load.js?upid=10b829af3eef17eb203667f5db56ef930eca062fde4a523b from the script tag. 它们要么返回空白,要么从脚本标记返回此URL http://0.0.0.0:3000/load.js?upid=10b829af3eef17eb203667f5db56ef930eca062fde4a523b

Any help would be great 任何帮助都会很棒

for future reference, I solved this by grabbing the URL through javascript, within the file thats included in the script tag. 为了将来参考,我通过在script标记中包含的文件中通过javascript抓取了URL来解决了这个问题。 Then, because that file is processed by rails first, I was able to send it into a method call with an erb tag to do what I wanted. 然后,由于该文件首先由rails处理,因此我能够将其发送到带有erb标签的方法调用中,以执行所需的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM