Rails: How can I register which site has javascript embedded?

My site provides javascript that shows the speed of the Dutch equivalent of the Dow Jones Index. Users can embed this script into their website.

It looks like this:

<script type="text/javascript" src="http://www.aexscript.nl/r/gratis"></script>

      

The corresponding controller action looks like this:

def show
  @script = Script.find_by_code(params[:code])
  @rate = Rate.find(:first)

  respond_to do |format|
    format.js # show.js.erb
  end
end

      

I want to record the url of a site where javascript has been embedded. How can i do this?

0


a source to share


2 answers


Create a database table that records your hits. Whenever someone shows a show, record it.

You can copy my code for something like this from http://github.com/saizai/hyperdictionary - take the controller, model and migration of four_oh_four.

If you have other information (for example, you know that the logged in user is somehow known, do you know whose link it is?), You can easily add it to this table as a foreign key. Then you would do something like



user.js_hits.find(:all, :select => "name, count(id) as count", :group => 'name')

      

And leave that in a simple view (see my app / views / four_oh_fours / index.html.erb for a simple example).

+2


a source


Your web server should provide you with access logs; which will show you every HTTP request received.

Then you can just grep for requests to that file.



Apache example

+2


a source







All Articles