Devise create various forms, among them one for signing up and one for logging in of course. These are the forms as they are generated in Devise 1.0.8:
<h2>Sign up</h2> <% form_for resource_name, resource, :url => registration_path(resource_name) do |f| -%> <%= f.error_messages %><%= f.label :email %> <%= f.text_field :email %> <%= f.label :password %> <%= f.password_field :password %> <%= f.label :password_confirmation %> <%= f.password_field :password_confirmation %> <%= f.submit "Sign up" %> <% end -%> <%= render :partial => "shared/devise_links" %>
and
<h2>Sign in</h2> <% form_for resource_name, resource, :url => session_path(resource_name) do |f| -%><%= f.label :email %> <%= f.text_field :email %> <%= f.label :password %> <%= f.password_field :password %> <% if devise_mapping.rememberable? -%><%= f.check_box :remember_me %> <%= f.label :remember_me %> <% end -%><%= f.submit "Sign in" %> <% end -%> <%= render :partial => "shared/devise_links" %>
If you try to put them somewhere else you’ll run into some problem. There are some variables/methods those forms use that you’ll be lacking, specifically: resource_name, resource and for logging in also devise_mapping. I’ve recently tried to put them both in the homepage for an upcoming project of mine and this is how I’ve solved it:
module ContentHelper def resource_name :user end def resource @resource ||= User.new end def devise_mapping @devise_mapping ||= Devise.mappings[:user] end end
Leave a Reply