Missing devise routes - ruby-on-rails

Rails 5.1
Devise
My routes.rb file:
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
devise_for :users, controllers: {
sessions: 'users/sessions',
confirmations: 'users/confirmations',
passwords: 'users/passwords',
registrations: 'users/registrations',
unlocks: 'users/unlocks',
invitations: 'users/invitations'
}
root to: "landings#index"
resources :users
resources :followeds
resources :followers
resources :locations
resources :fw_exports
get 'import_spreadsheet', to: :upload_spreadsheet, controller: 'fw_exports'
post 'parse_imported_spreadsheet_and_confirm', to: :process_imported_spreadsheet_and_confirm, controller: 'fw_exports'
post 'process_parsed_spreadsheet', to: :process_parsed_spreadsheet, controller: 'fw_exports'
scope module: :landings do
get 'visitors'
end
end
When I generate routes, here's what I get:
Prefix Verb URI Pattern Controller#Action
new_user_session GET /users/sign_in(.:format) users/sessions#new
user_session POST /users/sign_in(.:format) users/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) users/sessions#destroy
new_user_password GET /users/password/new(.:format) users/passwords#new
edit_user_password GET /users/password/edit(.:format) users/passwords#edit
user_password PATCH /users/password(.:format) users/passwords#update
PUT /users/password(.:format) users/passwords#update
POST /users/password(.:format) users/passwords#create
cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel
new_user_registration GET /users/sign_up(.:format) users/registrations#new
edit_user_registration GET /users/edit(.:format) users/registrations#edit
user_registration PATCH /users(.:format) users/registrations#update
PUT /users(.:format) users/registrations#update
DELETE /users(.:format) users/registrations#destroy
POST /users(.:format) users/registrations#create
accept_user_invitation GET /users/invitation/accept(.:format) users/invitations#edit
remove_user_invitation GET /users/invitation/remove(.:format) users/invitations#destroy
new_user_invitation GET /users/invitation/new(.:format) users/invitations#new
user_invitation PATCH /users/invitation(.:format) users/invitations#update
PUT /users/invitation(.:format) users/invitations#update
POST /users/invitation(.:format) users/invitations#create
root GET / landings#index
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
followeds GET /followeds(.:format) followeds#index
POST /followeds(.:format) followeds#create
new_followed GET /followeds/new(.:format) followeds#new
edit_followed GET /followeds/:id/edit(.:format) followeds#edit
followed GET /followeds/:id(.:format) followeds#show
PATCH /followeds/:id(.:format) followeds#update
PUT /followeds/:id(.:format) followeds#update
DELETE /followeds/:id(.:format) followeds#destroy
followers GET /followers(.:format) followers#index
POST /followers(.:format) followers#create
new_follower GET /followers/new(.:format) followers#new
edit_follower GET /followers/:id/edit(.:format) followers#edit
follower GET /followers/:id(.:format) followers#show
PATCH /followers/:id(.:format) followers#update
PUT /followers/:id(.:format) followers#update
DELETE /followers/:id(.:format) followers#destroy
locations GET /locations(.:format) locations#index
POST /locations(.:format) locations#create
new_location GET /locations/new(.:format) locations#new
edit_location GET /locations/:id/edit(.:format) locations#edit
location GET /locations/:id(.:format) locations#show
PATCH /locations/:id(.:format) locations#update
PUT /locations/:id(.:format) locations#update
DELETE /locations/:id(.:format) locations#destroy
fw_exports GET /fw_exports(.:format) fw_exports#index
POST /fw_exports(.:format) fw_exports#create
new_fw_export GET /fw_exports/new(.:format) fw_exports#new
edit_fw_export GET /fw_exports/:id/edit(.:format) fw_exports#edit
fw_export GET /fw_exports/:id(.:format) fw_exports#show
PATCH /fw_exports/:id(.:format) fw_exports#update
PUT /fw_exports/:id(.:format) fw_exports#update
DELETE /fw_exports/:id(.:format) fw_exports#destroy
import_spreadsheet GET /import_spreadsheet(.:format) fw_exports#import_spreadsheet
parse_imported_spreadsheet_and_confirm POST /parse_imported_spreadsheet_and_confirm(.:format) fw_exports#parse_imported_spreadsheet_and_confirm
process_parsed_spreadsheet POST /process_parsed_spreadsheet(.:format) fw_exports#process_parsed_spreadsheet
visitors GET /visitors(.:format) landings#visitors
Am I not supposed to also be getting routes for confirmatins and unlocks?

The problem is you have commented the lockable & confirmable. You need to uncomment it inorder to make it work.
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable, :lockable
end

Related

Creating a route works in one branch, but not the other

I have created a new "public_speaking" route by adding an entry in pages_controller.rb:
def public_speaking
end
I also created a barebones view file for "public_speaking.html.erb" and added a route in routes.rb as follows:
get 'home/public_speaking'
-or-
get 'public_speaking', to: 'pages#public_speaking'
I have tried both versions of the route and it worked in one of my branches, but I tried copying and pasting the code into another branch and the same steps don't yield any entry for a "public_speaking" route when I run "rails routes" in my console.
What on earth could cause a new route to be created in one branch but not another? What else should I try?
The full routes.rb file looks like this:
Rails.application.routes.draw do
root to: "pages#home"
get 'home/public_speaking'
get 'public_speaking', to: 'pages#public_speaking'
devise_for :users, controllers: { registrations: 'users/registrations' }
resources :users do
resource :profile
end
get 'about', to: 'pages#about'
resources :contacts, only: [:create]
get 'contact-us', to: 'contacts#new', as: 'new_contact'
get 'home/public_speaking'
get 'public_speaking', to: 'pages#public_speaking'
end
The full pages controller looks like:
class PagesController < ApplicationController
# GET request for / which is our home page
def home
#basic_plan = Plan.find(1)
#pro_plan = Plan.find(2)
end
def about
end
def offerings
end
def public_speaking
end
end
Editing to add the results of "rails routes" for the working branch:
rails routes
Prefix Verb URI Pattern Controller#Action
pages_home GET /pages/home(.:format) pages#home
pages_about GET /pages/about(.:format) pages#about
pages_offerings GET /pages/offerings(.:format) pages#offerings
pages_public_speaking GET /pages/public_speaking(.:format) pages#public_speaking
root GET / pages#home
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel
user_registration POST /users(.:format) users/registrations#create
new_user_registration GET /users/sign_up(.:format) users/registrations#new
edit_user_registration GET /users/edit(.:format) users/registrations#edit
PATCH /users(.:format) users/registrations#update
PUT /users(.:format) users/registrations#update
DELETE /users(.:format) users/registrations#destroy
user_profile POST /users/:user_id/profile(.:format) profiles#create
new_user_profile GET /users/:user_id/profile/new(.:format) profiles#new
edit_user_profile GET /users/:user_id/profile/edit(.:format) profiles#edit
GET /users/:user_id/profile(.:format) profiles#show
PATCH /users/:user_id/profile(.:format) profiles#update
PUT /users/:user_id/profile(.:format) profiles#update
DELETE /users/:user_id/profile(.:format) profiles#destroy
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
about GET /about(.:format) pages#about
contacts POST /contacts(.:format) contacts#create
new_contact GET /contact-us(.:format) contacts#new
offerings GET /offerings(.:format) pages#offerings
ubuntu#ip-172-31-91-225:~/environment/saasapp$
And the branch where it doesn't work:
rails routes
Prefix Verb URI Pattern Controller#Action
root GET / pages#home
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel
user_registration POST /users(.:format) users/registrations#create
new_user_registration GET /users/sign_up(.:format) users/registrations#new
edit_user_registration GET /users/edit(.:format) users/registrations#edit
PATCH /users(.:format) users/registrations#update
PUT /users(.:format) users/registrations#update
DELETE /users(.:format) users/registrations#destroy
user_profile POST /users/:user_id/profile(.:format) profiles#create
new_user_profile GET /users/:user_id/profile/new(.:format) profiles#new
edit_user_profile GET /users/:user_id/profile/edit(.:format) profiles#edit
GET /users/:user_id/profile(.:format) profiles#show
PATCH /users/:user_id/profile(.:format) profiles#update
PUT /users/:user_id/profile(.:format) profiles#update
DELETE /users/:user_id/profile(.:format) profiles#destroy
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
about GET /about(.:format) pages#about
contacts POST /contacts(.:format) contacts#create
new_contact GET /contact-us(.:format) contacts#new
offerings GET /offerings(.:format) pages#offerings

How can I access the profiles/show.html.erb in rails app

I´m using Devise, and after signing up, I want my users to access the profiles/show.html.erb
I have an registrations_controller.rb and in there I have this piece of code
def after_sign_up_path_for(resource)
new_user_profile_path(current_user)
end
It directs the user to profiles/new.html.erb but I want the user to go to profiles/show.html.erb
the rake routesshows this paths:
new_user_profile GET /users/:user_id/profile/new(.:format) profiles#new
edit_user_profile GET /users/:user_id/profile/edit(.:format) profiles#edit
GET /users/:user_id/profile(.:format) profiles#show
how would I modify this chunk of code to direct to the profiles/show.html.erb?
I'm to unexperienced to figure this out by my self, any help would be greate
this is my routes.rbfile
Rails.application.routes.draw do
devise_for :users, :controllers => { registrations: 'registrations' }
resources :users do
resource :profile
end
root 'pages#index'
end
** Edit**
the rake routes output
Prefix Verb URI Pattern Controller#Action
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) registrations#cancel
user_registration POST /users(.:format) registrations#create
new_user_registration GET /users/sign_up(.:format) registrations#new
edit_user_registration GET /users/edit(.:format) registrations#edit
PATCH /users(.:format) registrations#update
PUT /users(.:format) registrations#update
DELETE /users(.:format) registrations#destroy
user_profile POST /users/:user_id/profile(.:format) profiles#create
new_user_profile GET /users/:user_id/profile/new(.:format) profiles#new
edit_user_profile GET /users/:user_id/profile/edit(.:format) profiles#edit
GET /users/:user_id/profile(.:format) profiles#show
PATCH /users/:user_id/profile(.:format) profiles#update
PUT /users/:user_id/profile(.:format) profiles#update
DELETE /users/:user_id/profile(.:format) profiles#destroy
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
GET /%20/users/:user_id/profile(.:format)%20 profiles#show
root GET / pages#index
I fixed it, check your github.
Spelling of your resource is wrong
It should be resources :profile not resource :profile
that is why it was not showing you the paths to the profile resources through rake routes command.
I used the profile_path(current_user) in the show action at profile_controller.rb file
In your controller you need to create
def show
end
You can also try replacing your code in registration controller with.
def after_sign_up_path_for(resource)
show_user_profile_path(current_user)
end
remove 'do' from resources :users do in routes.rb file.
def after_sign_up_path_for(resource)
user_path(current_user)
end
rake routes shows user GET /users/:id(.:format) users#show
routes.rb
get 'profiles/show', to: 'profiles/show', as: :profile
profiles_controller.rb
def show
unless params[:user_id] #user = User.find(current_user.id)
#user = User.find(params[:user_id])
end
and then
def after_sign_up_path_for(resource)
profile_path
end

Proper way of rails routing custom Users controller and devise gem

Im having a problem routing my custom Users controller and devise gem.
When i try to reach http://localhost:3000/users
<%= link_to 'Users', users_path, class: 'navbar-brand' %>
I get error:
Could not find devise mapping for path "/users". This may happen for two reasons:
1) You forgot to wrap your route inside the scope block. For example: devise_scope :user do get "/some/route" => "some_devise_controller" end
2) You are testing a Devise controller bypassing the router. If so, you can explicitly tell Devise which mapping to use: #request.env["devise.mapping"] = Devise.mappings[:user]
If i run command rake routes i get this output:
Prefix Verb URI Pattern Controller#Action
root GET / static_pages#home
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
user_confirmation POST /users/confirmation(.:format) devise/confirmations#create
new_user_confirmation GET /users/confirmation/new(.:format) devise/confirmations#new
GET /users/confirmation(.:format) devise/confirmations#show
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
account_update PATCH /account_update(.:format) users#update
And this are my routes
root 'static_pages#home'
devise_for :users
resources :users
as :user do
patch 'account_update' => 'users#update'
get 'users' => 'users#index'
end
How to tell rails that on /users it should go to controller Users and select index page
You can try something like that,
devise_for :users
devise_scope :user do
end

Rails 3.2.1: link works on app, is present in routes.rb but doesn't show up on rake routes output

I have these urls:
http://localhost:3000/assets
http://localhost:3000/assets/new
http://localhost:3000/assets/34
http://localhost:3000/assets/34/edit
they work in my app.
I have this routes.rb file:
devise_for :users
match "listings/show_notes" => "listings#show_notes", :as => :show_notes
resources :users
resources :listings
resources :assets
authenticated :user do
root :to => "listings#index"
end
#this route is for file downloads
match "assets/get/:id" => "assets#get", :as => :download
resources :admin_dash_board, :only => :index
I have the following output when I type in rake routes
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
show_notes /listings/show_notes(.:format) listings#show_notes
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
listings GET /listings(.:format) listings#index
POST /listings(.:format) listings#create
new_listing GET /listings/new(.:format) listings#new
edit_listing GET /listings/:id/edit(.:format) listings#edit
listing GET /listings/:id(.:format) listings#show
PUT /listings/:id(.:format) listings#update
DELETE /listings/:id(.:format) listings#destroy
root / listings#index
admin_dash_board_index GET /admin_dash_board(.:format) admin_dash_board#index
As you can see there are no routes for the resource :assets.
Any idea why? Or whats going on?
Thanks
I think I found your answer here and here.
Try to add this line in your application.rb:
config.assets.prefix = "/new_route"
EDIT - also here with some other options to solve the problem....

Rails 3 + Devise - How to get nested resources / routes to work?

In my routes.rb file, the only entries I have are:
devise_for :users, :path => "accounts"
resources :users do
resource :profile
end
but when I run "rake routes" I can see that there are still mapped resources for the user i.e new, create, edit, update etc...this is causing a conflict with some of the devise paths such as new_user_registration_path
new_user_session GET /accounts/sign_in(.:format) devise/sessions#new
user_session POST /accounts/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /accounts/sign_out(.:format) devise/sessions#destroy
user_password POST /accounts/password(.:format) devise/passwords#create
new_user_password GET /accounts/password/new(.:format) devise/passwords#new
edit_user_password GET /accounts/password/edit(.:format) devise/passwords#edit
PUT /accounts/password(.:format) devise/passwords#update
cancel_user_registration GET /accounts/cancel(.:format) devise/registrations#cancel
user_registration POST /accounts(.:format) devise/registrations#create
new_user_registration GET /accounts/sign_up(.:format) devise/registrations#new
edit_user_registration GET /accounts/edit(.:format) devise/registrations#edit
PUT /accounts(.:format) devise/registrations#update
DELETE /accounts(.:format) devise/registrations#destroy
user_profile POST /users/:user_id/profile(.:format) profiles#create
new_user_profile GET /users/:user_id/profile/new(.:format) profiles#new
edit_user_profile GET /users/:user_id/profile/edit(.:format) profiles#edit
GET /users/:user_id/profile(.:format) profiles#show
PUT /users/:user_id/profile(.:format) profiles#update
DELETE /users/:user_id/profile(.:format) profiles#destroy
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
How can I get rid of the additional user resources which are appearing at the bottom of this output?
If you only wanted, say, index and show, try:
devise_for :users, :path => "accounts", :only => [:index, :show] do
resource :profile
end
The best way to do this would be to define your Devise (not nested) routes using 'devise_for:', and then in a separate block, do
resources :users, :only => :none do
resource :profile
end
Using ':except => :all' stops any non-nested Users routes from being defined and overriding your Devise routes, but it still creates all of your users/3/profile routes. Then add :path => "accounts" to replace users
So your code would look like
devise_for :users, :path => "accounts"
resources :users , :path => "accounts", :only => :none do
resource :profile
end

Resources