在设计 Simple_Form_For 将新表单发布到设计注册控制器中自定义新用户注册页面的路由
[英] Customize Route to New User Registration Page in Devise Simple_Form_For Posting new form to Devise Registration Controller
本文介绍了在设计 Simple_Form_For 将新表单发布到设计注册控制器中自定义新用户注册页面的路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个想法 - 我应该制作一个继承注册控制器的新控制器吗?然后再做一个
devise_for :users, :controllers =>{:注册=>新控制器"}
将我的 trial_signup.html.erb 改为 new.html.erb
并在 app/views/devise/registrations2/new.html.erb 中创建一个新文件夹
最新更新app/views/devise/trial_signup.html.erb
试用注册
<%= simple_form_for(resource, :as => resource_name, :url => sales_path(resource_name)) 做 |f|%><div class="row"><div class="col-xs-6 col-md-6"><%= f.input :first_name, :autofocus =>真,:input_html =>{ :class =>表单控制"}%>
<div class="col-xs-6 col-md-6"><%= f.input :last_name, :input_html =>{ :class =>表单控制"}%>
<%= f.input :email, :required =>真,:input_html =>{ :class =>表单控制"}%><%= f.input :password, :required =>真,:input_html =>{ :class =>表单控制"}%><%= f.input :password_confirmation, :required =>真,:input_html =>{ :class =>表单控制"}%><%= f.button :submit, class: "btn-lg btn-primary btn-block" %><%结束%>
- 这会在销售时呈现我的 trial_signup.html.erb,但是当我提交它寻找 user.sales 并且没有创建用户时.
<小时>
我有一个 user.rb 模型
has_many :trial_subscriptionsattr_accessible :trial_subscriptions_attributesaccepts_nested_attributes_for :trial_subscriptions, :allow_destroy =>真的
我有一个 trial_subscription.rb 模型,它继承自 manual_subscription.rb 并继承自 subscription.rb
Subscription.rb 模型
belongs_to :user
<小时>
我的任务是创建一个trial_signup.html.erb来发布表单(创建用户及其相关的试用账户)
我正在努力学习设计和 simple_form_for.
<小时>
在我的路线中
我有这个
devise_for :users, :controllers =>{:注册=>注册"}
如果我去 users/sign_up 我正在渲染 app/views/devise/registrations/new.html.erb
我将 new.html.erb 的相同副本复制到了
中的 trial_signup.html.erb
app/views/devise/registrations/trial_signup.html.erb
我将此添加到我的路线
devise_scope :user do获取销售",到:注册#trial_signup"结尾
我可能弄错了 devise_scope 的用途.我不完全理解这部分.
我是否使用指向注册试用注册操作的用户模型获取销售页面?请注意,我希望trial_signup.html.erb 在注册控制器中点击create 方法(来自devise).它是否在我的注册控制器中执行了一个空的 trial_signup 操作?
我的表格里有这个
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|%>
- 这使我的trial_signup.html.erb 处于销售状态,但没有发布
<小时>
当我做耙路线时,我有这个
new_user_registration GET/users/sign_up(.:format) registrations#new销售 GET/sales(.:format) 注册#trial_signup
**我没有注册路径?它有什么用?
解决方案
更新
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|%>
与
<%= simple_form_for(resource, :as => resource_name, :url => sales_path) do |f|%
>
Do rake routes
并检查为 get "sales"
路由生成的路径(主要是 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.
这篇关于在设计 Simple_Form_For 将新表单发布到设计注册控制器中自定义新用户注册页面的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!