好的,所以我想使用twitter bootstrap模态来显示设计登录表单.
我基于我的维基文章的代码在这里:
https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app
<div class="modal fade" id="loginModal"> <div class="modal-header"> <button class="close" data-dismiss="modal">×</button> <h3>Sign In</h3> </div> <div class="modal-body"> <%= simple_form_for(resource,:as => resource_name,:url => session_path(resource_name),:html => {:class => 'form-horizontal'}) do |f| %> <div class="inputs"> <%= f.input :email,:required => false,:autofocus => true %> <%= f.input :password,:required => false %> <%= f.input :remember_me,:as => :boolean if devise_mapping.rememberable? %> </div> </div> <div class="modal-footer"> <%= f.button :submit,"Sign in",:class => 'btn btn-primary',:data => { :dismiss => "modal"} %> <% end %> </div> </div>
而且,按照wiki中的建议,将以下内容添加到应用程序帮助文件中
def resource_name :user end def resource @resource ||= User.new end def devise_mapping @devise_mapping ||= Devise.mappings[:user] end
解决方法
这是最终工作的代码
<%= simple_form_for(:user,:url => user_session_path) do |f| %>