Rails not finding one of my controllers - ruby-on-rails

I'm trying to customize the after sign up path in my Devise registrations. Per the instructions I created a new controller called therapists_registrations_controller.rb, but when I start the server and load a page I get ActionController::RoutingError (uninitialized constant TherapistsRegistrationsController).
Now therapists_registrations_controller.rb is in app/controllers/api/therapists_registrations_controller.rb, all the other controllers load and I'm not playing any games with autoload_paths or anything. What could be the problem?
This is on Rails 3.2.11. Code for the controller is:
class TherapistsRegistrationsController < Devise::RegistrationsController
protected
def after_inactive_sign_up_path_for(resource)
"http://google.com"
end
end

One of the reason could be the class name. As you have therapists_registrations_controller.rb inside the app/controllers/api, the class name should be
class Api::TherapistsRegistrationsController < Devise::RegistrationsController
Update:
You should also change this
devise_for :therapists, :controllers => { :registrations => "therapists_registrations" }
to
devise_for :therapists, :controllers => { :registrations => "api/therapists_registrations" }

Related

Session Value not set in ror devise form

i had three ror devise forms...so i thought of adding after_sign_up_path_for .its working perfectly but the problem i am having is one of the forms using session hascode..when its redirected it shows hashcode is not set...
i tried lot of thins but its working when i add devise_for :users alone in routes.rb the session code is set but if i add this line ,session is not set but all three forms are redirecting correctly..
devise_for :users, :controllers => {:registrations => "registrations"}
i am not sure what is causing the problem..please anybody help...
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
if resource.planner_type == "planner"
'/path1/invited_new'
elsif resource.planner_type == "bride"
'/path2/invited_new'
else
'/path3/invited_new'
end
end
end

how to overwrite devise controllers?

I have the devise SessionController overwrited:
on app/controllers/customers/sessions_controller.rb
class Customers::SessionsController < Devise::SessionsController
before_filter :destroy_cart, only: :destroy
def destroy_cart
cart = Cart.find(current_client.cart.id)
cart.destroy
end
end
but the cart is never destroyed, even if I overwrite the destroy method directly and add the super after my code, the cart its still there, in the database (I knkow I could create the cart just once and get it when the user logs in again or create a new one when he use the app for first time, but I want to try it this way for now), is like if is not reading my code on that SessionController.
and for some reason even when I have my views this way:
app/views/customer/registrations
the changes that I do on that views are only reflected if I change it to
app/views/devise/registrations
my routes.rb is:
devise_for :clients, :controllers => { sessions: 'customers/sessions'}
devise_scope :client do
root to: "customers/Sessions#new"
end
the model that I am using with devise is Client
why I cant destroy the cart in the devise controller?
and why I cant use the views/customer/sessions if the documentation it says I can/have to do it?
thank you for reading.
you can always try to do
def destroy
cart = Cart.find(current_client.cart.id)
cart.destroy
super
end
but first you might want to ensure that you really overwritten devise's controller correctly.
The reason why you can't see changes done to app/views/customer/registrations is beacuse you seems to overwrite only :sessions controller, so you need to change
devise_for :clients, :controllers => { sessions: 'customers/sessions'}
to
devise_for :clients, :controllers => { registrations: 'customers/registrations', sessions: 'customers/sessions'}
The last question is:
" why I cant use the views/customer/sessions if the documentation it says I can/have to do it? "
You have a typo here, you are using customers namespace, not customer in routes.rb [ sessions: 'customers/sessions' ] - just a typo?
Watch your spelling. The before_filter is calling a method that doesn't exist.

Using Devise Gem with namespaces throwing ActionController::RoutingError

Ok, I've seen a ton of different answers for how to get Devise working when using namespaces in your app, but none of them are working for me.
I have my app split up into three namespaces
Home (the public landing pages)
Account (the logged in profile/account of the user)
Admin (the admin backend which isn't written yet)
I've also split up all the partials into a base folder in each namespace. So each of my controllers inherit from the BaseController which inherits from the ApplicationController:
module Account
class UsersController < BaseController
end
end
And I created a sessions_controller.rb in both account and home that inherits from the devise sessions controller like this:
module Account
class SessionsController < BaseController < Devise::SessionsController
end
end
The goal is to have a login/ registration form in the Home namespace that lets users login to the users controller that is in the account namespace.
Right now when I click on the link generated by:
<%= link_to "register", new_user_registration_path %>
I'm getting
ActionController::RoutingError at /users/sign_up
uninitialized constant Account::RegistrationsController
My routes.rb file looks like this:
scope :module => "account" do
devise_for :users, :controllers => { :sessions => "account/sessions" }
resource :users
end
scope :module => "home" do
resources :home, :about, :jobs, :terms, :privacy, :android_availability, :about, :contact
end
get "home/index"
root :to => 'home::home#index'
end
The home controllers use a home layout and the account controllers use the application layout. I specify layout "home" in the home controllers, but I don't specify layout "application" in the account controllers because application is the default layout rails looks for.
Ok. I think I've covered all my bases. Any idea what I'm doing wrong here?
Thanks!
EDIT:
Ok, I've added a registrations_controller.rb file to the account namespace in the same way as the sessions_controller.rb file described above.
I also updated the routes.rb file:
scope :module => "account" do
devise_for :users, :controllers => {
:sessions => "account/sessions",
:registrations => "account/registrations" }
resource :users
end
Now I'm getting a new error that I don't understand. Here it is:
NoMethodError at /users/sign_up
undefined method `action' for Account::RegistrationsController:Class
It says the undefined method 'action' is in (gem) actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb which doesn't make any sense.
Specifically is says the problem is here:
def dispatch(controller, action, env)
controller.action(action).call(env)
end
EDIT 2:
Here is the code from my registrations_controller.rb
module Account
class RegistrationsController < BaseController < Devise::RegistrationsController
end
end
EDIT 3:
module Account
class BaseController < ApplicationController
end
end
Ok, the above is my base_controller.rb, which just inherits from the ApplicationController. All the other controllers inherit from BaseController. Because I've split my app into three namespaces, the base_controller is there to tell the other controllers in the namespace that the partials are in a folder named base within their namespace. As shown in this RailsCast
I get a missing partial error if I don't incude the BaseController because the devise controllers can't find the partials.
Read your errors! :-)
For starters, looks like you need to define an Account::RegistrationsController, the same way you did your Account::SessionsController.

Rails 3 devise user registration edit path not working

I have a pretty straight forward app with a couple tweaks to Devise.
First I created a Registrations controller that class RegistrationsController < Devise::RegistrationsController inherits from Devise. I created this controller so that I could edit users without re-supplying passwords. https://gist.github.com/1514687
I also did this in my routes:
devise_for :users, :controllers => { :registrations => "registrations" }`
The signup works fine but when I call the following:
<p class="edit"><%= link_to "Edit", edit_user_registration_path(user) %></p>
The url it spits out is (running on localhost): http://localhost:3000/users/edit.2
Any ideas here?
I recommend a non-devise controller for doing this, and name it something other that "users" for the sake of not overlapping with devise routes
some key nomenclature:
rails g controller accounts
resources :accounts
def edit
#user = User.find(params[:id]
end
(other controller actions similar, just refer to #user and don't worry about that this happens to be called the accounts controller)
In your routes.rb file make sure that you have
resources :users
after your devise_for line like below:
devise_for :users, :controllers => { :registrations => "registrations" }
resources :users

Setup devise with custom registration controller

I'm working on a rails site using devise, where we do not want user sign ups just yet. User authentication is so we can login to access restricted parts of the site and add/edit things as we see fit. So for now, I created the following controller:
class Users::RegistrationController < Devise::SessionsController
def new
end
end
And setup my routes in this fashion:
devise_for :users, :controllers => { :registration => "users/registration" }
However, when I run rake routes, I still see a returned value for the create action on the registration controller. Any ideas on how to get rid of it?
Try using :registrations instead of :registration. Also, it seems like your custom controller class should be defined via:
class Users::RegistrationsController < Devise::RegistrationsController

Resources