Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting devise sign_in form into Twitter Bootstrap Modal

Okay, so I want to use the twitter bootstrap modal to display the devise sign-in form.

I am basing my code of the wiki article here: https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app

I have the below markup in my application layout file

<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>

And, following the advice in the wiki, added the following to the application helper file

def resource_name
  :user
end

def resource
  @resource ||= User.new
end

def devise_mapping
 @devise_mapping ||= Devise.mappings[:user]
end

It however, does not work. The modal dismisses and nothing happens. The page doesn't go anywhere or do anything. Going to the actual sign-in page works, but submitted the modal does not. Suggestions?

like image 618
DVG Avatar asked May 30 '12 01:05

DVG


1 Answers

This is the code that ended up working

<%= simple_form_for(:user, :url => user_session_path) do |f| %>
like image 63
DVG Avatar answered Oct 06 '22 00:10

DVG