Skip to content

Instantly share code, notes, and snippets.

@gavinhughes
Created January 8, 2012 21:45
Show Gist options
  • Save gavinhughes/1579810 to your computer and use it in GitHub Desktop.
Save gavinhughes/1579810 to your computer and use it in GitHub Desktop.
Devise Issue #1553
<-- registrations/email/edit.html.erb -->
<h2>Change Email</h2>
<%= form_for(resource, :as => resource_name, :url => { registrations_email_path(resource) }, :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
<div><p><strong>Current email:</strong></p>
<p><%= resource.email %></p></div>
<div><%= f.label :new_email %><br />
<%= f.email_field :new_email %></div>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<div><%= f.submit "Change email" %></div>
<% end %>
<-- registrations/password/edit.html.erb -->
<h2>Change Password</h2>
<%= form_for(resource, :as => resource_name, :url => { registrations_password_path(resource) }, :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<div><%= f.label :new_password %><br />
<%= f.email_field :new_password %></div>
<div><%= f.label :new_password_confirmation %><br />
<%= f.password_field :new_password_confirmation %></div>
<div><%= f.submit "Change password" %></div>
<% end %>
<-- registrations/show.html.erb -->
<h2>Your Account</h2>
<ul>
<li><strong>Email:</strong><%= resource.email %><%= link_to 'Change it', edit_registrations_email_path %></li>
<li><%= link_to 'Change your password', edit_registrations_password_path %></li>
<li><%= button_to "Cancel your account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>
</ul>
@schadenfred
Copy link

This is a cool idea. I'm thinking of writing a wiki entry on how to split up password and email changes on this. Would you write the routes in a devise_scope block? Also, would you use separate password and email controllers? Thanks!

@gavinhughes
Copy link
Author

I do routes for accounts like this:

Site::Application.routes.draw do

  devise_for :users, skip: :registration do
    resource :account, only: [:show, :new, :create] do
      resource :email, only: [:edit, :update], controller: 'accounts/email'
      resource :password, only: [:edit, :update], controller: 'accounts/password'
    end
end

I don't use 'registrations'. As I see it, when a user signs up, he's got an 'account', not a 'registration'.

You could even one (big) step further and patch Devise. José and I and have discussed this and I think he would probably accept it. If not, the fork would become very popular.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment