My site provides a javascript that shows the rate of the Dutch equivalent of the Dow Jones index. Users can embed this script in 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 log the URL of the site the javascript has been embedded on. How can I do this?
Make a database table that logs your hits. Whenever someone hits show, log it.
You can rip my code for something similar from http://github.com/saizai/hyperdictionary – take the four_oh_four controller, model, & migration.
If you have other information (eg you know the logged on user somehow? you know whose link it is?) you can easily add it to that table as a foreign key. Then you’d do something like
And drop it in a simple view (see my app/views/four_oh_fours/index.html.erb for a simple example).