Show a devise log in form in another page

Update: there’s a new version of this post covering Devise 4.0.0: Show a devise log in or sign up forms in another page

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 %>
  <p><%= f.label :email %></p>
  <p><%= f.text_field :email %></p>

  <p><%= f.label :password %></p>
  <p><%= f.password_field :password %></p>

  <p><%= f.label :password_confirmation %></p>
  <p><%= f.password_field :password_confirmation %></p>

  <p><%= f.submit "Sign up" %></p>
<% end -%>

<%= render :partial => "shared/devise_links" %>

and

<h2>Sign in</h2>

<% form_for resource_name, resource, :url => session_path(resource_name) do |f| -%>
  <p><%= f.label :email %></p>
  <p><%= f.text_field :email %></p>

  <p><%= f.label :password %></p>
  <p><%= f.password_field :password %></p>

  <% if devise_mapping.rememberable? -%>
    <p><%= f.check_box :remember_me %> <%= f.label :remember_me %></p>
  <% end -%>

  <p><%= f.submit "Sign in" %></p>
<% 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

Don't ignore the technology!

Technology is making the word more efficient. At some point, communicating with a person far away, required writing down the message with ink in a piece of dead tree and have someone or some company physically move that to the other location. Now we fire an email and it’ there in seconds.

I’m actually not sure if in that case we are more efficient (global communication infrastructure vs global transportation infrastructure and gas for the trucks and planes), we are definitely faster.

Recently my oven broke. The door is not stoping when it should and goes almost all the way to the floor when you open it. I’ve notified the management company and wanting to make the process more efficient I’ve recorded a video of the issue and sent it to them. Ah, technology, love it!

Today the repair main arrived (at 7:30hs, very Swiss). He open the door and… “Ah! It’s broken, I’ll come back next week with the spare parts.”

Honestly I wasn’t surprised, but we already have the technology to make this whole thing more efficient, I did my part and I was ignored. I bet the apartment management company never sent the guy the video.

Overview of my new Extra 300S

http://vimeo.com/moogaloop.swf?clip_id=13983943&server=vimeo.com&show_title=1&show_byline=1&show_portrait=1&color=ffffff&fullscreen=1&autoplay=0&loop=0

Some pictures of the building process and the finished result:

[flickr-gallery mode=”photoset” photoset=”72157624560393349″]