Rails 5.1에서 Devise 4.2.1을 사용하고 있습니다. 우리의 애플 리케이션은 MixPanel의 JavaScript 라이브러리를 사용하여 익명의 웹 사이트 방문자가 탐색 할 때 고유 한 ID를 제공합니다.Devise 사용자 등록시 임의의 매개 변수 전달
사용자가 계정을 만들면 익명 ID를 데이터베이스의 알려진 사용자 ID에 연결합니다. 우리는 등록 양식에 숨겨진 필드에 사용자의 익명 mixpanel_id
를 삽입하고, 고안의 등록 컨트롤러에 다른 가입 데이터와 함께이를 게시하여이 작업을 수행 :
= vertical_form_for(resource, as: resource_name, url: registration_path(resource_name) do |f|
= f.input :name
= f.input :email
= f.input :password
= f.input :mixpanel_id, as: :hidden, input_html: { value: '' }
:javascript
after_load_once(function() {
mixpanel_promise.then(function (mixpanel) {
var id = mixpanel.get_distinct_id();
$('#user_mixpanel_id').val(id);
});
});
그리고 우리는 궁리의 방법을 만들 오버라이드 (override) :
를class RegistrationsController < Devise::RegistrationsController
def create
super
if resource.valid?
$mixpanel.alias(resource.id, params[:user][:mixpanel_id]) if params[:user][:mixpanel_id]
end
end
end
이것은 우리에게 잘 작동하는 것으로 보입니다. 사람들은 실제로 연결되어 있으며 사람들이 올바르게 연결되지 않은 이상한 행동을 발견했지만 사이트를 통해 자신의 행동을 바로 추적 할 수 있습니다. 오늘 조사하는 동안 나는 로그에 뭔가 발견 : Unpermitted parameter: :mixpanel_id
내가 강한 매개 변수로 보았다,하지만 :mixpanel_id
는 사용자에 저장된 속성이 없기 때문에, 나는 여기에 허용 된 매개 변수로 추가하는 방법을 잘 모르겠어요 :
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
end
end
전설에 허용! 고맙습니다. 그게 내가 놓친거야. –