Skip to content

Instantly share code, notes, and snippets.

@osiro
Created April 2, 2016 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osiro/9e88cf69c9c8c3f40362dd0de857cef4 to your computer and use it in GitHub Desktop.
Save osiro/9e88cf69c9c8c3f40362dd0de857cef4 to your computer and use it in GitHub Desktop.
class TrackingsController < ApplicationController
def create
@tracking = Tracking.create(tracking_params)
render json: { success: true }
end
private
def tracking_params
params.require(:tracking).permit(:ip, :url)
end
end
@osiro
Copy link
Author

osiro commented Apr 2, 2016

class TrackingsController < ApplicationController
  def create
    data = tracking_params.merge(ip: request.remote_id)
    @tracking = Tracking.create(data)
    render json: { success: true }
  end

private

  def tracking_params
    params.require(:tracking).permit(:ip, :url)
  end
end

@osiro
Copy link
Author

osiro commented Apr 2, 2016

$('a').click (e) ->
  # exemplo: "http://www.icasei.com.br/sobre"
  url = e.currentTarget.href

  $.ajax
    url: '/trackings'
    method: 'POST'
    data:
      tracking:
        ip: url

@osiro
Copy link
Author

osiro commented Apr 2, 2016

$('a').click(function(e) {
  var url = e.currentTarget.href;
  $.ajax(url: '/trackings', method: 'POST', data: { tracking: { ip: url } });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment