I was implementing the gem Devise in RubyOnRails and everything was working perfectly.
Then I went to add the "confirmable" module. I took the following steps:
I added :confirmable
to Usuarios.rb
:
class Usuario < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
# adicionado por mim
:confirmable
end
I created the migration file:
class AddConfirmableToUsuarios < ActiveRecord::Migration
def change
change_table(:usuarios) do |t|
t.string :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
t.string :unconfirmed_email
end
end
end
In the views I had to correct some urls by adding usuario
in the helpers, for example:
new_confirmation_path(resource_name)
# para
new_usuario_confirmation_path(resource_name)
But when I submit the form in views/devise/confirmation/new.html.erb
I get code 406 "not accptable" and error ActionController::UnknownFormat in Devise::ConfirmationsController#create
. Nevertheless, the confirmation email is sent and the link sent is valid and the account can be validated.
Follow the form below:
<h2>Resend confirmation instructions</h2>
<%= form_for(resource, as: resource_name, url: usuario_confirmation_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %></div>
<div><%= f.submit "Resend confirmation instructions" %></div>
<% end %>