I am new to Ruby on Rails,I am using Devise gem for authentication on table account_user.
When I do rake routes I get
new_account_user_session GET /account_users/sign_in(.:format)account_user/sessions#new
So my login page is xyz.com/account_users/sign_in.
I want to change the sign-in page to just xyz.com
I don't have any routes for the same in my routes.rb file, I thought devise is automatically generating routes for this.
Is there a way I can add alias/override for this devise generated routes, or redirect user to xyz.com instead of xyz.com/account_users/sign_in
set root to devise sign_in, so in your route file there should be
devise_for :account_users
devise_scope :account_user do
root to: 'devise/sessions#new'
end
this will set your root path to sign_in
or if you want to rename the route to 'login'
devise_for :account_users
devise_scope :account_user do
get 'login', to: 'devise/sessions#new'
end
more here https://github.com/plataformatec/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes
Related
I have a rails 5.2 application, using devise 4.4.3, which has two devise models: User and Parent.
The paths are defined the config/routes.rb as:
devise_for :users, path: 'users'
devise_for :parents, path: 'parents'
Currently when I visit an action that required authentication in an unauthenticated session I'm getting redirected to a /parents/sign_in, but I want to specify /users/sign_in as the default unauthenticated path.
How can I achieve this?
Add an unauthenticated call and define the default root route:
unauthenticated do
root to: "users#sign_in"
end
I am trying to route root to devise sign in path under a subdomain constraint.
My config/routes.rb look something like this
Rails.application.routes.draw
constraints subdomain: 'admin' do
devise_scope :admin do
root to: 'devise/sessions#new'
# here I override devise routes
end
end
root to: 'pages#homepage'
# rest of the routes
end
I am getting the error Could not find devise mapping for path "/".
Any suggestions as to how I route to root path in a subdomain with devise scope?
Thanks
To add an authentication constrain to a route use the devise authenticated method:
Rails.application.routes.draw
constraints subdomain: 'admin' do
authenticated :admin do
# the root page for authenticated users
root 'admin#dashboard', as: :authenticated_root
end
root to: 'devise/sessions#new'
end
# this is for no subdomain
root to: 'pages#homepage'
end
Im using rails 4.1.1 and ruby 2.1.1 and am having an issue with devise, namely my routes..I have used this many times before
devise_for :users
get 'pages/index'
# Route to Devise Login Page
devise_scope :user do
root to: "devise/sessions#new"
end
# Directing the user after login
authenticated :user do
root :to => 'pages#index'
end
But i get the error
`add_route': Invalid route name, already in use: 'root' (ArgumentError)
when trying to start the server.. I can see that root is being used twice, but like i said i have been able to do this in the past.. Is there a way around this
Thanks
Found this helpful comment here on stackoverflow
For Rails 4.0 you have to make sure you have unique names for the path
helpers, like root to: "dashboard#show", as: :authenticated_root.
Otherwise the authenticated root and the normal root route end up
having the same name for their path helpers, which Rails 4.0 no longer
allows
so I changed my authenticated root to helper like so
# Directing the user after login
authenticated :user do
root :to => 'pages#index', as: :authenticated_root
end
I'm new to rails and I'm using devise to authenticate users.
I have a devise User model and I'm using devise views.
my routes.rb file goes like this
Freshconnection::Application.routes.draw do
root to: 'pages#home'
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
devise_for :users do
ActiveAdmin.routes(self)
get '/users/sign_out' => 'devise/sessions#destroy'
end
As of now when I run the server, the request is routed to pages#home which is my landing page.
I want the users/sign_up page to be the landing page so that the user can sign_up and start using the website.
Please guide me on how this has to be accomplished.
Many thx
As described here (link) you could try the workaround
devise_scope :user do
root to: "devise/registrations#new"
end
Change your root directive to:
root to: 'devise/registrations#new'
I am using Devise for authenticating a Rails application. I am now able to successfully route /users/sign_in and /users/sign_out to /sign_in and /sign_out via this code in routes.rb:
devise_for :user, :as => ''
How do I map /registration/sign_up to /sign_up?
So that sign_in, sign_out, and sign_up all have the same pattern.
Note that I am using Devise only for users. No admins.
You need to add the following block to your routes.rb file:
devise_scope :user do
get "/sign_up" => "devise/registrations#new"
end
It's explained in: http://github.com/plataformatec/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes