2

I have started on a web application for user registration etc. using devise gem. I am novice to Ruby/Rails env. So this is part of my training.

My question is very similar to an old posting @ devise overriding registrations controller - uninitialized constant Users::RegistrationsController

After the homepage displays, when I click on signup button, I get this error. I have done some research on this issue on the web to no avail.

In app/controllers/users/registrations_controllers.rb I have this code:

   class Users::RegistrationsController < Device::RegistrationsController

    def create
      super do |resource|
        if params[:plan]
           resource.plan_id = params[:plan]
           if resource.plan_id == 2
              resource.save_with_payment
           else
              resource.save
           end
         end
       end
     end  
    end

In Routes.rb I have this line of code:

    devise_for :users, :controllers => { :registrations =>         'users/registrations' }

Please let me know if you need any other information to help resolve this error.

Community
  • 1
  • 1
joship
  • 21
  • 1
  • 4
  • 1
    Try `app/controllers/users/registrations.controllers.rb` it should be `registrations_controller.rb`. rename file name – Sonalkumar sute Mar 20 '15 at 12:01
  • Instead of using the shortcut notation `Users::RegistrationsController`, try wrapping it in a `Users` module: `module Users; class RegistrationsController` – janfoeh Mar 20 '15 at 12:03
  • @Sontya actually I have it as registrations_controller.rb and not as registrations.controller.rb and its still not working. – joship Mar 20 '15 at 12:15
  • @janfoeh I am not sure how to do that, so if you could elaborate I would really appreciate it...this is my first app and still trying to understand all the crazy terminology! – joship Mar 20 '15 at 12:17
  • There's also a typo in the first line: `Device::RegistrationsController ` – niiru Mar 20 '15 at 12:36
  • @joship https://gist.github.com/janfoeh/711a5043491e904a2305 – janfoeh Mar 20 '15 at 12:38
  • @janfoeh - you also used `Device` in your code – Sonalkumar sute Mar 20 '15 at 12:49
  • @niiru Thanks for noticing another typo! but the error still exists after correcting it and restarting Webrick server. – joship Mar 20 '15 at 12:53
  • @Sontya tried your way also, same error persists! – joship Mar 20 '15 at 12:54
  • @janfoeh tried the module Users per your suggestion, restarted server, still no change! – joship Mar 20 '15 at 12:57
  • where is `sign_up` button, where is that page is located, show the path. and your user model too – Sonalkumar sute Mar 20 '15 at 13:00
  • @Sontya https://github.com/joshipv/saas_app if you want to see the entire app so far.. – joship Mar 20 '15 at 13:35
  • Thanks everyone. So finally what worked was moving the registrations_controller out of app/controller/users folder back into app/controller itself. I am in disbelief as whatever I was taught is once again negated. This is the reality of software development business we have come to live with. – joship Mar 20 '15 at 13:44
  • What branch? I don't see the controller anywhere. – janfoeh Mar 20 '15 at 14:33
  • hey this can be closed out now...I have found the solution myself which was moving the registrations_controller out of users folder and back into it. Strange but true. Its hard to understand the way rails works sometimes. I am ending this now. Thank you all for your time. – joship Mar 21 '15 at 15:23

1 Answers1

2

In routes.rb, try:

devise_for :users,
  :skip => [:registrations, :sessions]

as user do
  # Registrations
  get   '/signup'   => 'users/registrations#new', as: :new_user_registration
  post  '/signup'   => 'users/registrations#create', as: :user_registration

It should work.

Chris Yeung
  • 2,613
  • 6
  • 34
  • 57
  • THANK YOU SO MUCH! I was looking for hours on how to stop Devise overriding controllers and didn't see this anywhere. This finally solved my problem. – Aron Oct 17 '16 at 21:07