0
votes

I am attempting to use the Devise Gem in my rails app for authentication when a user signs up. But when I go to my rails console to check the User table it does not have the new user created in the database. I tried to override the Devise Registration controller with my signup controller but no luck. The Registration controller does not appear to be setting the create method so that it can be created in the database. Can anyone offer any assistance with where I am going wrong?

What is showing in the server logs after a user signs up:

Started GET "/users/sign_up?utf8=%E2%9C%93&authenticity_token=ruu1To891VYxDpsZlU4HjeAatrsX%2BQXcjj0WVpFexExAaEuKxQEDhrNl8GNqeu30lcaiwJFED7H40cmqXH%2FxpA%3D%3D&user%5Bemail%5D=fake.email%40gmail.com&user%5Bpassword%5D=[FILTERED]&commit=Sign+up" for ::1 at 2016-10-08 11:14:49 -0500 Processing by Devise::RegistrationsController#new as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"ruu1To891VYxDpsZlU4HjeAatrsX+QXcjj0WVpFexExAaEuKxQEDhrNl8GNqeu30lcaiwJFED7H40cmqXH/xpA==", "user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}, "commit"=>"Sign up"} Rendered devise/registrations/new.html.erb within layouts/application (3.6ms)

Sign Up Page new.html.erb:

<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->  
<!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->  
<!--[if !IE]><!--> <html lang="en"> <!--<![endif]-->  
<head>
   <title>Sign Up</title>

</head> 

   <body class="signup-page access-page has-full-screen-bg">
   <div class="upper-wrapper">
    <!-- Header -->
    <!-- ******Signup Section****** --> 
    <section class="signup-section access-section section">
        <div class="container">
            <div class="row">
                <div class="form-box col-md-8 col-sm-12 col-xs-12 col- md-offset-2 col-sm-offset-0 xs-offset-0">     
                    <div class="form-box-inner">
                        <h2 class="title text-center">Sign up now</h2>  
                        <p class="intro text-center">It only takes 3 minutes!</p>               
                        <div class="row">
                            <div class="form-container col-md-5 col-sm-12 col-xs-12">
                                <form class="signup-form">
                                    <%= form_for(resource, as:  resource_name, url: user_registration_path(resource_name)) do |f| %>         <%= devise_error_messages! %>           
                                    <div class="form-group email">
                                        <!-- <label class="sr-only"   for="signup-email">Your email</label>
                                        <input id="signup-email"  type="email" class="form-control login-email" placeholder="Your email"> -->
                                        <%= f.label :email, class: 'sr-only' %>
                                        <%= f.text_field :email, class: 'form-control login-email', placeholder: "Your email" %>
                                    </div><!--//form-group-->
                                    <div class="form-group password">
                                        <%= f.label :password, class: 'sr-only' %>
                                        <%= f.text_field :password,     class: 'form-control login-password', placeholder: "Your password" %>
                                    </div>
                                    <!--//form-group-->
                                    <div class="col-md-12 col-sm-12     col-xs-12 form-group">
                                    <%= f.submit "Sign up", class: 'btn btn-block btn-cta-primary' %>
                                </div>
                                    <p class="note">By signing up, you    agree to our terms of services and privacy policy.</p>
                                    <p class="lead">Already have an    account? <%= link_to "Log in", user_session_path, class: "login-link" %> 
                                    </p>
                                    <% end %>
                                </form>
                            </div><!--//form-container-->
                            <div class="social-btns col-md-5 col-sm-12 col-xs-12 col-md-offset-1 col-sm-offset-0 col-sm-offset-0">  
                                <div class="divider"><span>Or</span></div>                      
                                <ul class="list-unstyled social-login">
                                    <li><button class="twitter-btn btn"    type="button"><i class="fa fa-twitter"></i>Sign up with Twitter</button></li>
                                    <li><button class="facebook-btn   btn" type="button"><i class="fa fa-facebook"></i>Sign up with Facebook</button></li>
                                    <li><button class="github-btn btn"     type="button"><i class="fa fa-github-alt"></i>Sign up with Github</button></li>
                                    <li><button class="google-btn btn" type="button"><i class="fa fa-google-plus"></i>Sign up with Google</button></li>
                                </ul>
                                <p class="note">Don't worry, we won't     post anything without your permission.</p>
                            </div><!--//social-login-->
                        </div><!--//row-->
                    </div><!--//form-box-inner-->
                </div><!--//form-box-->
            </div><!--//row-->
        </div><!--//container-->
    </section><!--//signup-section-->
 </div><!--//upper-wrapper-->
 <!--FOOTER -->

 <!-- Javascript -->          
 <script>
    /* ======= Fixed header when scrolled ======= */    
$(window).on('scroll load', function() 
{

     if ($(window).scrollTop() > 0) 
     {
         $('#header').removeClass('scrolled');
     }
     else 
     {
         $('#header').addClass('scrolled');

     }
});
</script>

Devise Registration Controller routes:

cancel_user_registration GET      /users/cancel(.:format)                devise/registrations#cancel
     user_registration POST     /users(.:format)                       devise/registrations#create
 new_user_registration GET      /users/sign_up(.:format)               devise/registrations#new
edit_user_registration GET      /users/edit(.:format)                  devise/registrations#edit
                       PATCH    /users(.:format)                       devise/registrations#update
                       PUT      /users(.:format)                       devise/registrations#update
                       DELETE   /users(.:format)                       devise/registrations#destroy

Attempt to override Devise Registration controller:

class SignupController::RegistrationsController <     Devise::RegistrationsController


 def new
  #@user = User.new
  @resource_name = User.new
 end

 def create
  @resource_name = User.new(user_params)


  #if @user.save
  if @resource_name.save
  flash[:notice] = "Your user account has been created!"
  create_session(@resource_name)
  redirect_to '/'

  else
   flash[:error] = "Your user account was not created, please try again."
  render :new
 end
end

def user_params
params.require(:user, :email)
end
end
1
Sorry but there is basically nothing right with the way you are bulldozering over devise. Can you include in the question why you are overriding the devise controller and what you want to achieve?max
Basically @resource_name in devise is the name of the user class - not the new user instance. @resource is the resource being created. And you really should not override the whole controller just to alter the views or add an extra attribute. I would start by reading the docs and the wiki as there are how to's for basically any scenario imaginable.max
I got it from this stack overflow post: stackoverflow.com/questions/13805695/…BV45

1 Answers

1
votes

Currently, there is one form inside another:

<form class="signup-form">
  <%= form_for... %>

However, it's not possible to nest forms. The outer form gets submitted and it gets submitted to the current page URL.

You need to remove the outer form and add signup-form class to the form_for:

<%= form_for(resource, as: resource_name, url: user_registration_path(resource_name), html: {class: 'signup-form'}) do |f| %>