Rails 4 と Devise 3.2.3 を使用しています。私のアプリでは、メールのみで新しいユーザーを作成できるログイン済みの管理者ユーザーを作成しようとしています。
ここの指示に従いました:
https://github.com/plataformatec/devise/wiki/How-To:-Email-only-sign-up
ビュー > 確認 > show.html.haml
%h2 You're almost done! Now create a password to securely access your account.
= semantic_form_for(resource, :as => resource_name, :url => confirm_path) do |form|
= devise_error_messages!
= form.inputs do
= form.input :password, :input_html => {:autofocus => true}
= form.input :password_confirmation
= form.input :confirmation_token, :as => :hidden
= form.actions do
= form.action :submit, :label => 'Confirm Account
確認_コントローラー
class ConfirmationsController < Devise::ConfirmationsController
def show
self.resource = resource_class.find_by_confirmation_token(params[:confirmation_token]) if params[:confirmation_token].present?
super if resource.nil? or resource.confirmed?
end
def confirm
self.resource = resource_class.find_by_confirmation_token(params[resource_name][:confirmation_token]) if params[resource_name][:confirmation_token].present?
if resource.update_attributes(params[resource_name].except(:confirmation_token).permit(:email, :password, :password_confirmation)) && 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
しかし、私の確認ショーアクションでは、次のエラーが発生します。
First argument in form cannot contain nil or be empty:
= semantic_form_for(resource, :as => resource_name, :url => confirm_path) do |form|
アップデート
問題は ConfirmationsController にあるようで、show アクションが機能していないようです。
リソース メソッドが機能していないようです。で出力しようとしています
class ConfirmationsController < Devise::ConfirmationsController
def show
self.resource = resource_class.find_by_confirmation_token(params[:confirmation_token]) if params[:confirmation_token].present?
# super if resource.nil? or resource.confirmed?
render text: self.resource.nil?
end
end
true を返します
また、「send_confirmation_instructions」で受け取った confirm_token は、データベース内のどのユーザー インスタンスにも属していません。