Deviseにルーティングの問題があり、理解できないと思います。ユーザーが認証にDeviseを使用してサインアップするために、このメソッドを実装しようとしています。この例ではhamlを使用しており、うまくいけばある程度の成功を収めて、それをerbに変換しようとしました。
Mac OSXで開発中のRails3.2.8、Deviseとsimple_formを使用したPostgresQLを使用
app / views / devise / registerrations / new.html.erb:
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%# simple_form_for([:backend, @user]) do |f| %>
<%= f.error_notification %>
<div class="inputs">
<%= f.input :email, :required => true, :autofocus => true, :label => "Email" %>
</div>
<div class="actions">
<%= f.button :submit, "Add User" %>
</div>
<% end %>
app / views / devise / confirmations / show.html.erb:
<%= simple_form_for(resource, :as => resource_name, :url => confirmation_path(resource_name)) do |f| %>
<div class="inputs">
<%= f.input :password, :required => true, :label => "Password" %>
<%= f.input :password_confirmation, :required => true, :label => "Confirm Password" %>
<%= f.hidden_field :confirmation_token %>
</div>
<div class="actions">
<%= f.button :submit, "Confirm" %>
</div>
<% end %>
app / modesl / user.rb:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable,
:timeoutable
# Setup accessible (or protected) attributes for your model
attr_accessible :email,
:password,
:password_confirmation,
:remember_me,
:username
def password_required?
super if confirmed?
end
def password_match?
self.errors[:password] << "can't be blank" if password.blank?
self.errors[:password_confirmation] << "can't be blank" if password_confirmation.blank?
self.errors[:password_confirmation] << "does not match password" if password != password_confirmation
password == password_confirmation && !password.blank?
end
end
app / controllers / confirmations_controller.rb:
class ConfirmationsController < Devise::ConfirmationsController
def show
self.resource = resource_class.find_by_confirmation_token(params[:confirmation_token])
super if resource.confirmed?
end
def confirm
self.resource = resource_class.find_by_confirmation_token(params[resource_name][:confirmation_token])
if resource.update_attributes(params[resource_name].except(:confirmation_token)) && resource.password_match?
self.resource = resource_class.confirm_by_token(params[resource_name][:confirmation_token])
set_flash_message :notice, :confirmed
sign_in_and_redirect(resource_name, resource)
else
render :action => "show"
end
end
end
app / config / routers.rb:
devise_for :users, :controllers => {:confirmations => 'confirmations'}
devise_scope :user do
put "/confirm" => "confirmations#confirm"
end
resources :users
users / sign_upページでメールアドレスを入力すると、すべて正常に機能します。確認メールを受け取り、確認リンクをクリックすると、次の場所に移動します。
/ users / confirmation?confirmation_token=[ここに確認トークン]
次に、パスワードを入力して送信すると、次のページに移動します。
ユーザー/確認
次のエラーが発生します。
UsersController#updateのActiveRecord::RecordNotFoundはid=confirmationのユーザーを見つけることができませんでした
ルーティングの問題だと確信しています。何か案は?本当にありがとう!