Customize Route to New User Registration Page in Devise Simple_Form_For Posting new form to Devise Registration Controller

笑着哭i 提交于 2019-12-02 20:16:14

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/22585749/customize-route-to-new-user-registration-page-in-devise-simple-form-for-posting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!