set devise users/sign_up page as landing page - ruby-on-rails

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'

Related

Logout path not working in activeadmin even after modifying the path in active_admin.rb

In my admin panel the logout link is not working. In my project I have removed the default admin user that is generated while installing the active admin and used the role from profile model to sign in as super_admin. My logout link is not working though. My /config/initializers/active_admin.rb is:
...
config.logout_link_path = :destroy_user_session_path
config.logout_link_method = :delete
...
My routes.rb file is given as:
Rails.application.routes.draw do
# Devise routes for registration, session and manual routes for confirmation and password
devise_for :users, controllers: {
confirmations: "users/confirmations",
passwords: "users/passwords"
} do
root to: "devise/sessions#new"
get '/users/sign_out', :to => 'devise/sessions#destroy'
end
# Route for super admin
ActiveAdmin.routes(self)
end
Thanks in advance for your input!!!
I got my logout link working by adding the active_admin.js file as I have deleted the file initially, as I thought it was not doing anything.

Alias for Devise URL Rails

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

Ruby on Rails - User Devise Routing

I'm having issues with routing with Devise and my Users model. I was trying to get sign_out to work and found an answer that suggested this.
// routes.rb
devise_for :users do
get '/users/sign_out' => 'devise/sessions#destroy'
get '/users/sign_in' => 'devise/sessions#create'
end
And while this works for signing out, if I use just that I cannot view a User.
No route matches [GET] "/users/1"
However, if I add back resources :users, I run into the first issue where sign_out or sign_in try to view a User.
Couldn't find User with 'id'=sign_out
How do I add /users/index to the devise_for loop?
Thanks for your help.
Try adding resources :users after your devise_for block.
You can also use the following:
devise_for :users, path: '', path_names: { sign_in: 'login', sign_out: 'logout'}

Rails 4 + Devise: set default root route for authenticated users

I have done some research and seen that this question has already been addressed several times, in different places:
Devise with rails 4 authenticated root route not working
Different '/' root path for users depending if they are authenticated (using devise)
Authenticated Route Constraints
Rails Tip #5: Authenticated Root and Dashboard Routes With Devise
I tried to follow the examples given in the links above and came up with the following solution, in my routes.rb file:
root to: 'pages#home'
devise_for :users, :path => 'account', controllers: { registrations: "registrations", confirmations: "confirmations" }
authenticated :user do
root 'calendars#index', as: :authenticated_root
end
The goal here is to direct unauthenticated users to the regular home page of the website, while authenticated users will go to their dashboard, inside the app, i.e. the calendars#index route, defined as follows in my routes:
calendars GET /calendars(.:format) calendars#index
However, when I log in as a user, and visit http://localhost:3000/, I keep landing on the regular home page of the website, instead of the user's dashboard inside the app.
What am I doing wrong?
Change routes.rb so that the unauthenticated root route is wrapped, just like the authenticated one:
devise_for :users, :path => 'account', controllers: { registrations: "registrations", confirmations: "confirmations" }
authenticated :user do
root 'calendars#index', as: :authenticated_root
end
unauthenticated :user do
root 'pages#home', as: :unauthenticated_root
end

Active Admin has taken over my routes completely

im building a basic ecommerce app to teach myself rails, and ive hit a problem. I had already installed devise and had two user models: 'users' and 'merchants'. I then installed active_admin and setup it's standard 'admin_user' model.
The admin section works as intended however now the view of every resource that active admin has access to has become the admin version.
Even my root now routes to the active admin login (assuming no one's logged in)
Any ideas as to why this is happening?
devise_for :merchants
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
devise_for :users
resources :products
resources :categories
resources :brands
get "static/about"
get "static/contact"
get "static/cookie"
get "static/faq"
get "static/help"
get "static/index"
get "static/privacy"
get "static/terms"
root :to => 'static#index'
The order in which rails parses route priority is from top to bottom so, first created -> highest priority. Active Admin also has a root :to => 'admin#dashboard route so your app is trying to load that as the main root route right now.
Try moving ActiveAdmin.routes(self) below your root :to => 'static#index'

Resources