登录后使用用户名渲染部分内容
render partial with username after a login
一个 rails 应用程序使用 devise omniauth 登录应用程序。
成功登录后,我想用显示@current_user.email
的html代码重新放置一个"Login"按钮
$(function() {
$('#facebook-connect').click(function(e) {
e.preventDefault();
FB.login(function(response) {
if(response.authResponse) {
$.ajax({
type: 'POST',
url: '/users/auth/facebook/callback',
dataType: 'json',
data: {signed_request: response.authResponse.signedRequest},
success: function(data, textStatus, jqXHR) {
$('#loginout_button').html("<%= j render(:partial => 'account_info') %>");
},
}
}
, {scope: 'email'});
});
});
和部分:
<% if user_signed_in? %>
<p class="text-left small"><%=current_user.email%></p>
<p class="text-left">
<%= link_to destroy_user_session_path, :method => :delete do %>
<%=t('auth.logout')%>
<% end%>
但是当然它不会工作,因为部分在页面加载时呈现,因此它会生成注销用户的模板:
$('#loginout_button').html(" <li>\n <button type=\"button\" onclick=\"openLoginModal(); return false;\">Login<\/button>\n <\/li>\n");
你应该如何根据设计@current_user状态生成模板。
您需要在 success
回调中发出另一个 ajax 请求以加载 account_info
模板。
一个 rails 应用程序使用 devise omniauth 登录应用程序。 成功登录后,我想用显示@current_user.email
的html代码重新放置一个"Login"按钮 $(function() {
$('#facebook-connect').click(function(e) {
e.preventDefault();
FB.login(function(response) {
if(response.authResponse) {
$.ajax({
type: 'POST',
url: '/users/auth/facebook/callback',
dataType: 'json',
data: {signed_request: response.authResponse.signedRequest},
success: function(data, textStatus, jqXHR) {
$('#loginout_button').html("<%= j render(:partial => 'account_info') %>");
},
}
}
, {scope: 'email'});
});
});
和部分:
<% if user_signed_in? %>
<p class="text-left small"><%=current_user.email%></p>
<p class="text-left">
<%= link_to destroy_user_session_path, :method => :delete do %>
<%=t('auth.logout')%>
<% end%>
但是当然它不会工作,因为部分在页面加载时呈现,因此它会生成注销用户的模板:
$('#loginout_button').html(" <li>\n <button type=\"button\" onclick=\"openLoginModal(); return false;\">Login<\/button>\n <\/li>\n");
你应该如何根据设计@current_user状态生成模板。
您需要在 success
回调中发出另一个 ajax 请求以加载 account_info
模板。