Hope everyone doing well.
Actually i am a newbie to Rails. I am making a mcqs type application for practice purpose. I use devise for this purpose. I create user model with devise and controller with devise.
But without using controller my application is working well but i am enable to redirect from one page to my willing page. Like i want to redirect from signup to login page but it's not redirecting me from signup to login. And when i use controller it says argument error when i remove argument error it shows params error. I don't know what to do please help me how can i redirect from one page to other.
Thanks.
CodePudding user response:
You need to change your routes for devise registrations
controller
devise_for :users, controllers: { registrations: 'registrations' }
And add this RegistrationsController
to your controllers and after_sign_up_path_for
method to it with path to redirect.
# app/controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
new_user_session_path
end
end
Note: If you use devise :confirmable
in your User
model you need to overwrite after_inactive_sign_up_path_for
# app/controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
protected
def after_inactive_sign_up_path_for(resource)
new_user_session_path
end
end
And don't forget to restart your server.
CodePudding user response:
If Rails 7, override the devise form (rails g devise:views) and custom view.
You will edit registrations/new
and sessions/new
form_for(resource, as: resource_name, url: session_path(resource_name) ) do |f|
replace
form_for(resource, as: resource_name, html: {'data-turbo' => "false"}, url: session_path(resource_name) ) do |f|
And change config/initializers/devise.rb
config.navigational_formats = ['*/*', :html, :turbo_stream]