简体   繁体   English

找不到在何处设计创建方法来创建用户

[英]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 我正在构建一个自定义表单,因此当用户输入trial_email时,该表单将创建一个具有关联的trial_subscription的新用户

The trial_subscription.rb model inherits from manual_subscription model and manual_subscription inherits from subscription model. trial_subscription.rb模型是从manual_subscription模型继承的,manual_subscription是从订阅模型继承的。

The subscription model 订阅模式

belongs_to :user

I need to build the associations from the has_many side. 我需要从has_many端建立关联。 Now I am having trouble figuring out where to post the form (getting the @user to be editted) when devise is involve. 现在,当涉及设计时,我很难弄清楚在哪里发布表单(让@user进行编辑)。 I need to know where the create method is when the user gets created and hence my question below. 我需要知道创建用户时create方法在哪里,因此下面是我的问题。

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. 这将是与/ sales网址中的普通注册分开的页面,因此我无法将嵌套字段添加到注册表单中。


The rails application that I am working on has devise installed on the user model. 我正在研究的Rails应用程序已设计安装在用户模型上。

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 注册表单位于views / devise / registrations / new.html.erb中

I have a users_controller.rb with a new and create method 我有一个具有new和create方法的users_controller.rb

in the users_controller.rb there is this before_filter 在users_controller.rb中有这个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? 没有User.new对象传递给视图进行编辑? 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? 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. 该用户具有has_many订阅关联,我需要发布一个同时创建用户及其订阅的表单。

You need to customize devise's registrations controller. 您需要自定义devise的注册控制器。 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. 那是您应该阅读的另一个主题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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