Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8720127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:57:44+00:00 2026-06-13T06:57:44+00:00

I’m using devise_invitable with devise in my Rails 3 app. I want to give

  • 0

I’m using devise_invitable with devise in my Rails 3 app. I want to give my users the ability to invite other users and group those invited users in advance of the invitees signing up.

My problem is that once the invitee comes along and signs up (but doesn’t use the invite URL), the destroy_if_previously_invited around_filter comes along, destroys the original user record and recreates a new record for the user, retaining the invitation data but not transferring the user_groups records along with it.

I’d like to simply override this around_filter by doing a search for any user_groups that match the originally invited user_id and saving them with the newly created user_id.

I keep getting the error:

LocalJumpError in Users::RegistrationsController#create

no block given (yield)

My route looks like this:

devise_for :users, :controllers => { :registrations => "users/registrations" }

I’ve set this as the override in 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

I may also just be going about this all wrong. Any ideas would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:57:45+00:00Added an answer on June 13, 2026 at 6:57 am

    First, there is no need to set the around_filter again, as devise_invitable already sets this. All you need to do is redefine the methods in your UsersController and those will be called instead of the devise_invitable ones.

    Second, it looks like you are combining the two methods when they should remain seperate and overridden (I am basing this off latest version of devise_invitatable 1.1.1)

    Try something like this:

    class Users::RegistrationsController < Devise::RegistrationsController
      protected
    
      def destroy_if_previously_invited
        hash = params[resource_name]
        if hash && hash[:email]
          resource = resource_class.where(:email => hash[:email], :encrypted_password => '').first
          if resource
            @old_id = resource.id #saving the old id for use in reset_invitation_info
            @invitation_info = Hash[resource.invitation_fields.map {|field|
              [field, resource.send(field)]
            }]
            resource.destroy
          end
        end
      end
    
      def reset_invitation_info
        # Restore info about the last invitation (for later reference)
        # Reset the invitation_info only, if invited_by_id is still nil at this stage:
        resource = resource_class.where(:email => params[resource_name][:email], :invited_by_id => nil).first
        if resource && @invitation_info
          resource.invitation_fields.each do |field|
            resource.send("#{field}=", @invitation_info[field])
          end
          ### Adding your code here
          if @old_id
            user_groups = UserGroup.find_all_by_user_id(@old_id)
            for user_group in user_groups do
              user_group.user_id = resource.id
              user_group.save!
            end
          end
          ### End of your code
          resource.save!
        end
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.