自定义路由到Devise中的新用户注册页面Simple_Form_For将新表单发布给Devise注册控制器 [英] Customize Route to New User Registration Page in Devise Simple_Form_For Posting new form to Devise Registration Controller

查看:105
本文介绍了自定义路由到Devise中的新用户注册页面Simple_Form_For将新表单发布给Devise注册控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个想法 - 我应该创建一个继承注册控制器的新控制器?然后再做另一个

  devise_for:users,:controllers => {:registration => newcontroller} 

将我的trial_signup.html.erb更改为new.html.erb



并在app / views / devise / registrations2 / new.html.erb中创建一个新文件夹



最新更新
app / views / devise / trial_signup.html.erb

 < h2>试用注册< ; / H2> 

<%= simple_form_for(resource,:as => resource_name,:url => sales_path(resource_name))do | f | %GT;

< div class =row>
< div class =col-xs-6 col-md-6>
<%= f.input:first_name,:autofocus => true,:input_html => {:class => form-control}%>
< / div>
< div class =col-xs-6 col-md-6>
<%= f.input:last_name,:input_html => {:class => form-control}%>
< / div>
< / div>
<%= f.input:email,:required => true,:input_html => {:class => form-control}%>
<%= f.input:password,:required => true,:input_html => {:class => form-control}%>
<%= f.input:password_confirmation,:required => true,:input_html => {:class => form-control}%>
<%= f.button:submit,class:btn-lg btn-primary btn-block%>
<%end%>
< / div>




  • 这会使我的trial_signup.html.erb销售,但是当我做提交其寻找user.sales并且不会创建用户。






我有一个user.rb模型

  has_many:trial_subscriptions 
attr_accessible:trial_subscriptions_attributes
acceptance_nested_attributes_for:trial_subscriptions,:allow_destroy => ;我有一个trial_subscription.rb模型,它继承于manual_subscription.rb,并从subscription.rb继承。



Subscription.rb模型

  belongs_to:user 






我的任务是创建一个trial_signup.html.erb来发布表单(创建用户及其关联的试用帐户)



我正在尝试学习devise和simple_form_for。





我有这个

  devise_for:users,:controllers => {:registrations => 注册} 

如果我去用户/ sign_up我正在渲染app / views / devise /注册/ new.html.erb



我将new.html.erb的相同副本复制到了


$中的trial_signup.html.erb b $ b

  app / views / devise / registrations / trial_signup.html.erb 

我添加到我的路线

  devise_scope:user do 
getsales到:注册#trial_signup
end

我可能误认了devise_scope的目的。我不完全明白这一点。



我是否使用指向注册试用注册操作的用户模型获取销售页面?请注意,我希望trial_signup.html.erb在注册控制器中点击create方法(from devise)。是否在我的注册控制器中打了一个空的trial_signup操作?



我以我的形式存在这个

 <%= simple_form_for (resource,:as => resource_name,:url => registration_path(resource_name))do | f | %GT; 




  • 这会使我的trial_signup.html.erb销售,但不发布






当我做耙路线我有这个

  new_user_registration GET /users/sign_up(.:format)注册#新
销售GET /sales(.:format)注册#trial_signup

**我没有注册路径?这是什么?

解决方案

更新

 code><%= simple_form_for(resource,:as => resource_name,:url => registration_path(resource_name))do | f | %GT; 



<%= simple_form_for(resource,:as => resource_name,:url => sales_path)do | f | %>



执行 rake路线,并检查生成的 getsales route(主要是user_sales_path:在前缀列下检查),将其作为 url 选项传递给表单。因为这样在表单提交你的自定义 RegistrationsController#trial_signup 行动将被调用。


an idea - should I be making a new controller that inherits the registrations controller? and then do another

devise_for :users, :controllers => {:registration => "newcontroller"}

change my trial_signup.html.erb to new.html.erb

and make a new folder in app/views/devise/registrations2/new.html.erb

Newest Update app/views/devise/trial_signup.html.erb

<h2>Trial Sign up</h2>

<%= simple_form_for(resource, :as => resource_name, :url => sales_path(resource_name)) do |f| %>

  <div class="row">
    <div class="col-xs-6 col-md-6">
      <%= f.input :first_name, :autofocus => true, :input_html => { :class => "form-control" } %>
    </div>
    <div class="col-xs-6 col-md-6">
      <%= f.input :last_name, :input_html => { :class => "form-control" } %>
    </div>
  </div>
    <%= f.input :email, :required => true, :input_html => { :class => "form-control" } %>
    <%= f.input :password, :required => true, :input_html => { :class => "form-control" } %>
    <%= f.input :password_confirmation, :required => true, :input_html => { :class => "form-control" } %>    
  <%= f.button :submit,  class: "btn-lg btn-primary btn-block" %>
  <% end %>
</div>

  • this renders my trial_signup.html.erb at sales but when I do submit its looking for user.sales and no user gets created.

I have a user.rb model

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

I have a trial_subscription.rb model that inherits from manual_subscription.rb and that inherits from subscription.rb

Subscription.rb model

belongs_to :user


My task is to create a trial_signup.html.erb to post the form (create the user and its associated trial accounts)

I am trying to learn devise and simple_form_for as I go.


in my routes

I have this

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

if I go to users/sign_up I am rendering the app/views/devise/registrations/new.html.erb

I made an identical copy of the new.html.erb to trial_signup.html.erb in

app/views/devise/registrations/trial_signup.html.erb

I added this to my routes

  devise_scope :user do
    get "sales", to: "registrations#trial_signup"
  end

I may have mistaken the purpose of devise_scope. I don't fully understand this part.

am i getting the sales page using the user model pointing to the registration trial signup action? Please note that I want the trial_signup.html.erb to hit the create method (from devise) in the registration controller. Is it hitting an empty trial_signup action in my registration controller?

I have this in my form

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>

  • this renders my trial_signup.html.erb at sales but its not posting

when I do rake routes I have this

new_user_registration GET        /users/sign_up(.:format)                                registrations#new
sales GET        /sales(.:format)                                        registrations#trial_signup

**I don't have a registration_path? what is it for?

解决方案

Update

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>

With

<%= simple_form_for(resource, :as => resource_name, :url => sales_path) do |f| %>

Do rake routes and check the path generated for get "sales" route(mostly user_sales_path: check under prefix column), pass it as url option to the form. Because of this upon form submission your custom RegistrationsController#trial_signup action would be called.

这篇关于自定义路由到Devise中的新用户注册页面Simple_Form_For将新表单发布给Devise注册控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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