Created
October 29, 2013 00:33
-
-
Save murdoch/7207279 to your computer and use it in GitHub Desktop.
Devise embed signup form on home page or anywhere else
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Stick form in home.html.erb | |
<h2>Sign up</h2> | |
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> | |
<%= devise_error_messages! %> | |
<div><%= f.label :email %><br /> | |
<%= f.email_field :email %></div> | |
<div><%= f.label :password %><br /> | |
<%= f.password_field :password %></div> | |
<div><%= f.label :password_confirmation %><br /> | |
<%= f.password_field :password_confirmation %></div> | |
<div><%= f.submit "Sign up" %></div> | |
<% end %> | |
<%= render "links" %> | |
# Then stick this in application_helper.rb | |
def resource_name | |
:user | |
end | |
def resource | |
@resource ||= User.new | |
end | |
def devise_mapping | |
@devise_mapping ||= Devise.mappings[:user] | |
end | |
# Perhaps add the following to view too: | |
<%= render "devise/shared/links" %> | |
# And maybe this to application helper also: | |
def resource_class | |
User | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment