How to add callback after registration with Rails3 and Devise

How to add a callback to create an account for the registered user.

Devise files (registrations_controller.rb) are under controllers/devise My user model has has_many :accounts relationship (and the account model has belongs_to :user)

First I don't know where to add the callback (what file?)

Then, how to automatically create a new account with the right user_id of the registered user?

Thanks in advance.

-------------Problems Reply------------

You can override devise's registration controller, add callback to create account using filters. Remember to name the file registrations_controller.rb

class RegistrationsController < Devise::RegistrationsController
after_filter :add_account


def add_account
if resource.persisted? # user is created successfuly

then in your routes.rb tell devise to use overrided controller for registration

devise_for :users, controllers: { registrations: 'registrations'}

Here's a thread on the google group that answers your question:

Basically it recommends just adding a standard rails "after_create" method to your user model to run the code you need.

Category:ruby on rails 3 Views:1 Time:2011-01-15

Related post

  • ui.tabs add callback not able to set tab 2010-02-04

    I am trying to get jQuery tabs to behave like IE and Firefox. I have a few tabs with an "addtab" at the end. When this tab is clicked a new tab is added, this is fine. But i want to select the second last tab. This is proving to be quite difficult. m

  • How can we add a payment registration in zen cart? 2011-08-18

    How can we add a payment registration in zen cart? right now the registration for zen cart is free, I would like to implement a payment module for that. Anyone know about such a plug in? --------------Solutions------------- It sounds as though your d

  • Rails3 and Devise as part of basic CRM 2011-08-21

    We've built a custom CRM for managing our customers and orders in Rails3 with devise for authentication and cancan doing the permission magic. Companies have many people, orders and invoices. Pretty simple. On top of this we have our users through de

  • How do I add custom javascript to my rails3 views? 2010-07-08

    What is the best way to add JavaScript to my Rails3 views? I would like to be able to do some processing in a controller, then craft some JavaScript based on the result and put the resulting JavaScript in a view. For example, I would like to get a se

  • JS add callback to run next function? 2010-09-29

    How do I add some sort of call back so that I can run further code after render() has completed? function next(){ target = max; render(); //When render complete, do some more //change values.... //render(); } function prev(){ target = min; render();

  • How can I add callbacks to jquery validation (when used in MVC 2) 2010-10-06

    I'm using jquery for validation in my MVC2 web app (as described here) and I'd like to wire up some callbacks that the jquery validation plugin supports, like invalidHandler, etc. I can manually edit the MicrosoftMvcJQueryValidation.js and add my cal

  • How to create a profile after user registration with Rails3 & Devise 2011-01-14

    I'm doing a simple user with profile application. User registers and are automatically logged in. Works fine so far. Now, I'd like to create a profile after a successful registration and redirect the user to his/her profile. I have a User model and c

  • How to add callback for appending text to TextArea or other stuff in a class that performs parsing? 2011-04-27

    I would like to know what is the best way in Java to add a callback (perhaps as argument since I'm using public static methods most of the time), to an external function, to do something like appending text to a text area control. I don't want to pas

  • How to add callback to AJAX variable assignment 2011-05-16

    I've got a variable responce which is assigned via an AJAX function send(). When I make the assignment... responce = send(); response returns before send does giving me back an undefined how can I add a callback to prevent this from happening? EDIT:

  • Add callback command on any tcl error in tcl script? 2011-05-25

    Is is possible to specify user defined command on error in tcl script? I want to cleanup the memory on if any error comes. I know that last error is saved in errorInfo variable. --------------Solutions------------- You can also define a bgerror proce

  • Add callback for when a Toast message closes 2011-06-26

    I have a Toast message I use as a splash screen which I would like to add a callback to once it closes. How is this achievable in Android? // Splash LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.splash, (ViewG

  • How to add callbacks to Framework Element's Visibility Dependency Property? 2011-10-11

    I'm using a dependency property which handles the fade-in / fade-out of a Framework Element. The property is able to handle the fade-in / fade-out animation by registering callback methods for whenever the Visibility property of the animated element

  • add callback to map with Google-Maps-for-Rails 2011-10-26

    I found stackoverflow topic on adding marker add marker with Google-Maps-for-Rails , but failed even in adding callback :( In , found that there were some changes in address

  • Joomla 1.6 Add Field to registration that requires a certain code in order to go through 2011-11-20

    So, I know how to add the field into the form I just can't get it to take the secret code and evaluate it. Files that I understand to be essential in doing this: /components/com_users/views/registration/tmpl/default.php /components/com_users/controll

  • How to add callback function in jQuery? 2012-02-29

    function $(id) { if (id) { if (window === this) { return new $(id); } this.e = document.getElementById(id); return this; } else { return about; } } $.prototype = { click: function () { this.e.onclick = function () { alert("hi.."); } } }; when I excut

  • Add to wordpress registration page 2014-09-11

    Im making a plugin for BuddyPress and want to add a "register with Linkedin" button to the registration page underneath or above the registration form. I cant figure out how to add to this page. I foud a way to add fields to the form but this is not

  • How to add callback function to a javascript class? 2009-01-19

    The following code in javascript gives me the error "this.callback is not a function function ajaxRequest() { var httpObject; = open; this.callback = function(){}; function getHTTPObject() { if (window.ActiveXObject) return new ActiveXObjec

  • Rails devise add fields to registration form when having STI 2011-01-11

    Here is my models: class User < ActiveRecord::Base has_one :worker, :class_name => 'Worker', :foreign_key => :worker_id devise :database_authenticatable accepts_nested_attributes_for :worker attr_accessible :worker_id, :email, :password, :pa

  • How to initiate new profile object (has_one) after successful registration with Rails3 & devise 2011-01-14

    So I have devise setup to perform registration. After registration the user is redirected to profiles#new however I can't attach profile to current_user id Actually it doesn't work at all. Here is what I have in my profiles_controller.rb # POST /prof

Copyright (C), All Rights Reserved.

processed in 0.092 (s). 11 q(s)