Rails3アプリで使用devise_invitable
しています。devise
招待者がサインアップする前に、他のユーザーを招待し、それらの招待されたユーザーをグループ化する機能をユーザーに提供したいと思います。
私の問題は、招待者が来てサインアップすると(ただし、招待URLは使用しない)、destroy_if_previously_invited
around_filterが来て、元のユーザーレコードを破棄し、ユーザーの新しいレコードを再作成して、招待データを保持しますが、 user_groupsはそれと一緒に記録します。
最初に招待されたuser_idに一致するuser_groupsを検索し、新しく作成されたuser_idと一緒に保存することで、このaround_filterを単純にオーバーライドしたいと思います。
エラーが発生し続けます:
LocalJumpError in Users::RegistrationsController#create
no block given (yield)
私のルートは次のようになります:
devise_for :users, :controllers => { :registrations => "users/registrations" }
これをapp/controllers / users/registrations_controller.rbのオーバーライドとして設定しました。
class Users::RegistrationsController < Devise::RegistrationsController
around_filter :destroy_if_previously_invited, :only => :create
private
def destroy_if_previously_invited
invitation_info = {}
user_hash = params[:user]
if user_hash && user_hash[:email]
@user = User.find_by_email_and_encrypted_password(user_hash[:email], '')
if @user
invitation_info[:invitation_sent_at] = @user[:invitation_sent_at]
invitation_info[:invited_by_id] = @user[:invited_by_id]
invitation_info[:invited_by_type] = @user[:invited_by_type]
invitation_info[:user_id] = @user[:id]
@user.destroy
end
end
# execute the action (create)
yield
# Note that the after_filter is executed at THIS position !
# Restore info about the last invitation (for later reference)
# Reset the invitation_info only, if invited_by_id is still nil at this stage:
@user = User.find_by_email_and_invited_by_id(user_hash[:email], nil)
if @user
@user[:invitation_sent_at] = invitation_info[:invitation_sent_at]
@user[:invited_by_id] = invitation_info[:invited_by_id]
@user[:invited_by_type] = invitation_info[:invited_by_type]
user_groups = UserGroup.find_all_by_user_id(invitation_info[:user_id])
for user_group in user_groups do
user_group.user_id = @user.id
user_group.save!
end
@user.save!
end
end
end
私もこれについてすべて間違っているかもしれません。任意のアイデアをいただければ幸いです。