discourse/app/controllers/clicks_controller.rb

30 lines
736 B
Ruby
Raw Normal View History

2013-02-06 03:16:51 +08:00
class ClicksController < ApplicationController
skip_before_filter :check_xhr
2013-02-07 23:45:24 +08:00
2013-02-06 03:16:51 +08:00
def track
params = track_params.merge(ip: request.remote_ip)
2013-02-06 03:16:51 +08:00
if params[:topic_id].present? || params[:post_id].present?
params.merge!({ user_id: current_user.id }) if current_user.present?
TopicLinkClick.create_from(params)
2013-02-06 03:16:51 +08:00
end
# Sometimes we want to record a link without a 302. Since XHR has to load the redirected
# URL we want it to not return a 302 in those cases.
if params[:redirect] == 'false'
render nothing: true
else
redirect_to(params[:url])
end
end
private
def track_params
params.require(:url)
params.permit(:url, :post_id, :topic_id, :redirect)
end
2013-02-07 23:45:24 +08:00
end