Session Value not set in ror devise form - ruby-on-rails

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

Related

Devise redirect on sign up

I know this question was asked several times. I tried them but none of them solved my problem. I used devise for users. I want to redirect the user to a different page on sign up rather than signing in directly. I created registration controller, and tried overriding "after_inactive_sign_up_path_for" but it didn't work out. I 'm using devise confirmable also. So until the user is verified I should redirect him to other page.
registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
protected
def after_inactive_sign_up_path_for(resource)
"http://www.google.com" # Or :prefix_to_your_route
end
end
routes.rb
devise_for :users, controllers: { registrations: "registrations" }
Next I tried to move the registrations into a different folder in the controllers folder. But that too didn't work out.
FYI: I'm using rails 5 and devise 4.2.1.
Your controller should be in the path app/controllers/users/registrations_controllers.rb.
Then your routes should be
devise_for :users, controllers: { registrations: "users/registrations" }

Rails not finding one of my controllers

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" }

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.

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