yel*_*ign 5 ruby-on-rails devise
我正在使用Devise和我的Rails 3.2应用程序,我希望能够在Google Analytics中添加跟踪新注册作为转换.我想让新用户定向到他们被重定向到现在的同一页面,如果可能的话(也就是说,可能是通过重定向到当前页面的用户被重定向到创建后的视图).
有人可以帮我找出使用Devise做到这一点的最佳方法吗?
# users/registrations_controller.rb
# POST /resource
def create
build_resource
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_with resource
end
end
def after_sign_up_path_for(resource)
after_sign_in_path_for(resource)
end
Run Code Online (Sandbox Code Playgroud)
jva*_*nte 10
从我的头顶,我会使用闪光灯.
在registrations_controller.rb:
if resource.active_for_authentication?
flash[:user_signup] = true # or something that you find more appropriate
set_flash_message :notice, :signed_up if is_navigational_format?
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
Run Code Online (Sandbox Code Playgroud)
然后,在您注册后重定向到的视图上,我将根据其存在情况呈现必要的代码以触发Google Analytics事件flash[:user_signup].
| 归档时间: |
|
| 查看次数: |
1894 次 |
| 最近记录: |