找不到devise创建方法创建用户的位置 [英] Can't find where devise create method to create user

查看:162
本文介绍了找不到devise创建方法创建用户的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已更新

我想添加更多详细信息。我有一个用户模型,这个用户模型

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

我正在构建一个自定义表单,所以当用户输入一个trial_email时,表单将创建一个新的具有相关联的trial_subscription的用户

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_subscription.rb模型继承于manual_subscription模型,而manual_subscription继承自订阅模式。

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

订阅模式

belongs_to :user

我需要从has_many方面构建关联。现在,当涉及到设计时,我无法确定在哪里发布表单(获取@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.

这将是一个单独的页面,正常注册在/ sales url所以我无法在注册表单中添加嵌套字段。

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.

我正在处理的rails应用程序已安装在

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

在路线中

我有

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

注册表单在视图/ devise /注册/ new.html.erb

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

我有一个users_controller.rb新的和创建方法

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

users_controller.rb有这个before_filter

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.

当我去

/users/sign_up  - there is the sign up page

如果我执行

   /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

没有将User.new对象传递给视图进行编辑?我猜这个设计不需要它。

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?

用户有一个has_many订阅关联,我需要发布一个既可以创建用户及其订阅的表单。

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

推荐答案

您需要自定义devise的注册控制器。请参阅它的文档
虽然该文档仅显示如何自定义会话控制器(登录),步骤类似,您只需要以不同的方式命名您的自定义控制器。

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.

这篇关于找不到devise创建方法创建用户的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆