简体   繁体   中英

Can't find where devise create method to create user

Updated

I want to add more details to this. I have a user model and this user model

has_many :trial_subscriptions
attr_accessible :trial_subscriptions_attributes
accepts_nested_attributes_for :trial_subscriptions, :allow_destroy => true

I am building a custom form so when a user enters a trial_email, the form will create a new user with an associated trial_subscription

The trial_subscription.rb model inherits from manual_subscription model and manual_subscription inherits from subscription model.

The subscription model

belongs_to :user

I need to build the associations from the has_many side. Now I am having trouble figuring out where to post the form (getting the @user to be editted) when devise is involve. I need to know where the create method is when the user gets created and hence my question below.

This will be a separate page from normal sign up in a /sales url so I can not add nested fields to the signup form.


The rails application that I am working on has devise installed on the user model.

In the routes

I have

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

the sign up form is in views/devise/registrations/new.html.erb

I have a users_controller.rb with a new and create method

in the users_controller.rb there is this before_filter

before_filter :authenticate_admin!

We have active admin installed. I am still quite new to the code. Since this filter exist I am sure the user is not getting created in this controller.

when I go to

/users/sign_up  - there is the sign up page

if I do

   /users/new - I am redirected to /users/sign_up 

so I am guessing that the user is getting created in the registrations controller but the new method is this

  def new
    session[:qbid] = params[:qbid]
    session[:trial] = params[:trial]
    session[:sublength] = params[:sublength]
    if session[:trial] = true
      @trial_flow = true
    end
    super
  end

there is no User.new object getting passed to the view to get edited? I am guessing that devise doesn't need it.

I am getting confused on where the user is getting created because my task is to create a custom form which creates a new user.

I don't know where to post the form to? the registrations_controller?

The user has a has_many subscriptions association and I need to post a form that both create the user and its subscriptions.

You need to customize devise's registrations controller. See it's doc Though the doc shows only how to customize the session controller (login), the steps are similar, you just need name your customized controller differently.

If you are wondering, you can see here how devises' controllers look. When you are customizing those, you are going to use inheritance. That is another topic you should read about.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM