我正在使用 rails 3.2.8 为一个大学项目构建一个类似博客的网站,我想使用来自 twitter bootstrap 的模态框来实现一个不显眼的登录系统。我已经尝试了一些关于这个主题的教程,但到目前为止我还不能让它工作。在会话控制器中,我有这个:
session_controller.rb
class SessionsController < ApplicationController
def new
respond_to do |format|
format.html
format.js
end
end
# Handling authentication when user submits login form
# with authenticate method. If the authentication is
# successful stores a permanent or temporary cookie based
# on selection :remember_me with an authorization token
# and redirects to root_url with notice else displays
# alert and redirects to new
def create
user = User.authenticate(params[:email], params[:password])
if user
if params[:remember_me]
cookies.permanent[:auth_token] = user.auth_token
else
cookies[:auth_token] = user.auth_token
end
redirect_to root_url, :notice => "Logged in!"
else
flash.now.alert = "Invalid email or password"
render "new"
end
end
# Deleting cookie and redirecting to root_url on
# logout with notice
def destroy
cookies.delete(:auth_token)
redirect_to root_url, :notice => "Logged out!"
end
end
在应用程序视图中,我创建了一个隐藏模式,其中应该呈现表单部分的内容以及a :remote => true
登录链接
应用程序.html.erb
<div class="modal hide fade" id = "modal">
<div class="modal-body">
</div>
</div>
.
.
.
<%= link_to(log_in_path, :remote => true) do %>
<i class="icon-check"></i> Log in
<% end %>
最后在 /app/views/sessions 有 js 视图
新的.js.erb
$("#modal-body").html(<%= escape_javascript render(:partial => 'form')%>);
$('#modal').modal('show');
但不是在模态rails中显示登录表单,而是将我带到登录页面(new.html.erb
)。谁能帮我这个?