0

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?

3
  • Why not just modify the new.html.erb? Is there any specific use case for which you are keeping two different sign up pages?
    – Kirti Thorat
    Mar 23, 2014 at 2:31
  • @KirtiThorat Hi the new.html.erb is for regular sign up and the trial_signup is for signing users for a trial. There are two purposes. I plan to have a custom form with nested attributes to build the association. A user model has many trial_subscriptions.
    – Jngai1297
    Mar 23, 2014 at 3:16
  • See my answer. Let me know if it works out for you.
    – Kirti Thorat
    Mar 23, 2014 at 3:30

1 Answer 1

0

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.

5
  • I updated the question, added some details and still running into trouble. I want the form to post to the create method in my custom controller that inherits from devise::registration not hitting the trial_signup action??
    – Jngai1297
    Mar 23, 2014 at 14:17
  • The form is getting rendered but I want
    – Jngai1297
    Mar 23, 2014 at 14:18
  • As per the rake routes, you have sales_path so update the path accordingly in the simple_form_for. See my updated answer for the same.
    – Kirti Thorat
    Mar 23, 2014 at 14:34
  • I have tried it. After I hit the save user button its looking for user.save and says route can't be found. I have also updated my question above.
    – Jngai1297
    Mar 23, 2014 at 14:45
  • I only have new should I have edit, create, and destroy in my routes as well?
    – Jngai1297
    Mar 23, 2014 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.