When trying to access Active Admin dashboard under http://localhost:3000/admin I get redirected to http://localhost:3000/users/sign_in. However my path shows the /admin path.
admin_root_path GET /admin(.:format) admin/dashboard#index
admin_dashboard_path GET /admin/dashboard(.:format) admin/dashboard#index
batch_action_admin_users_path POST /admin/users/batch_action(.:format) admin/users#batch_action
admin_users_path GET /admin/users(.:format) admin/users#index
and
new_user_session_path GET /users/sign_in(.:format) devise/sessions#new
user_session_path POST /users/sign_in(.:format) devise/sessions#create
Anyone know why this is happening?
EDIT
routes.rb
Myapp::Application.routes.draw do
ActiveAdmin.routes(self)
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
root 'static_pages#home'
match '/help', to: 'static_pages#help', via: 'get'
match '/about', to: 'static_pages#about', via: 'get'
match '/contact', to: 'static_pages#contact', via: 'get'
What is your routes.rb file looks like? The routes are loaded in the priority from top to bottom, that's why it's important that you place them in correct order.
Generally, ActiveAdmin routes should be loaded after Devise.
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
Try to move ActiveAdmin.routes(self) route to the very bottom (below standard root to:)
Related
I am getting this error message:
ArgumentError: You should not use the `match` method in your router without specifying an HTTP method.
If you want to expose your action to both GET and POST, add `via: [:get, :post]` option.
If you want to expose your action to GET, use `get` in the router:
Instead of: match "controller#action"
Do: get "controller#action"
Here is my routes.rb:
Rails.application.routes.draw do
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
root 'static_pages#home'
resources :contacts, only: [:new, :create]
resources :users
resources :account_activations, only: [:edit]
get '/help', to: 'static_pages#help'
get '/about', to: 'static_pages#about'
get '/subscribe', to: 'static_pages#subscribe'
get '/signup', to: 'users#new'
post '/signup', to: 'users#create'
get 'sessions/new', to: 'sessions#new'
get '/login', to: 'sessions#new'
post '/login', to: 'sessions#create'
get '/logout', to: 'sessions#destroy' , via: :delete
get '/resend', to: 'users#resend'
post '/resend_activation', to: 'users#resend_activation'
end
I will appreciate any help in locating what i have done wrong with my routing and how best to solve the problem.
in my routes.rb:
## The Humen routes by Devise
devise_for :humen, skip: [:sessions]
as :humen do
# sessions
get '/login(.:format)' => 'devise/sessions#new', as: :new_human_session
post '/login(.:format)' => 'devise/sessions#create', as: :human_session
delete 'logout' => 'devise/sessions#destroy', as: :destroy_human_session
end
However, upon going to localhost:3000/login I get:
Routing Error
Not Found
...
new_human_session_path GET /login(.:format) devise/sessions#new
human_session_path POST /login(.:format) devise/sessions#create
destroy_human_session_path DELETE /logout(.:format) devise/sessions#destroy
Which sucks. I can't for the life of me figure out what's wrong!
The code in the question was posted at the end of the routes.rb file, below get ':username' => 'paywall#profile' which meant that the :username route was being resolved before it got to /login
I moved the code to the top of the file and it works!
I believe you should change your devise routing code in your routes.rb file to something like below.
devise_scope :user do
get '/login(.:format)' => 'devise/sessions#new', as: :new_human_session
post '/login(.:format)' => 'devise/sessions#create', as: :human_session
get "logout", to: "devise/sessions#destroy", as: :logout
end
I have a problem, I follow this tutorial :https://richonrails.com/articles/google-authentication-in-ruby-on-rails.
I have done everything except rails g controller home show because I have already a static_pages controller and home.html.erb
So in my route.rb I have replace this line from the tutorial:
resource :home, only: [:show]
root to: "home#show"
by
resource :static_pages, only: [:home]
root to: 'static_pages#home'
but when I click on the link after I've launched the server (localhost) I have this error:
No route matches [GET] "/auth/google_oauth2"
Do you have any idea about this problem? Hope you could help me.
Thank you in advance.
EDIT : My route.rb code
Rails.application.routes.draw do
get 'sessions/create'
get 'sessions/destroy'
get 'sessions/new'
get 'users/new'
root 'static_pages#home'
get 'help' => 'static_pages#help'
get 'about' => 'static_pages#about'
get 'contact' => 'static_pages#contact'
get 'signup' => 'users#new'
get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
resources :users
end
GoogleAuthExample::Application.routes.draw do
get 'auth/:provider/callback', to: 'sessions#create'
get 'auth/failure', to: redirect('/')
get 'signout', to: 'sessions#destroy', as: 'signout'
resources :sessions, only: [:create, :destroy]
resource :static_pages, only: [:home]
root to: 'static_pages#home'
end
It work! I do that with devise. but just dont forget to install "mongoid" gem in order to set up devise (that took me lot of time to determine mogoid was missing).
Thank you all!
Hi im doing a kind of blog to learn Rails, using the Getting started tutorials like these
http://guides.rubyonrails.org/getting_started.html
http://guides.rubyonrails.org/routing.html
I have manage to do the posts sections and i also do a admin/posts section, this is the problem now..
Ths system is "conflicting" and admin goes to domain.com/posts instead of admin/posts.
I think the problem is the way i build the links..
In the tutorial to link a item yo do
<h2><%= link_to post.title, post %></h2>
I have tried
<h2><%= link_to post.title, admin_post_path %></h2>
And similars but i get
undefined local variable or method `admin_post_path' for #<#<Class:0x007fe3e990ef28>:0x007fe3e6e3b508>
How does this works i mean i have done rake routes and i see there the routes, but i cant use them
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) 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
PUT /users(.:format) registrations#update
DELETE /users(.:format) registrations#destroy
users GET /admin/users(.:format) admin/users#index
POST /admin/users(.:format) admin/users#create
new_user GET /admin/users/new(.:format) admin/users#new
edit_user GET /admin/users/:id/edit(.:format) admin/users#edit
user GET /admin/users/:id(.:format) admin/users#show
PUT /admin/users/:id(.:format) admin/users#update
DELETE /admin/users/:id(.:format) admin/users#destroy
posts GET /admin/posts(.:format) admin/posts#index
POST /admin/posts(.:format) admin/posts#create
new_post GET /admin/posts/new(.:format) admin/posts#new
edit_post GET /admin/posts/:id/edit(.:format) admin/posts#edit
post GET /admin/posts/:id(.:format) admin/posts#show
PUT /admin/posts/:id(.:format) admin/posts#update
DELETE /admin/posts/:id(.:format) admin/posts#destroy
players GET /players(.:format) players#index
POST /players(.:format) players#create
new_player GET /players/new(.:format) players#new
edit_player GET /players/:id/edit(.:format) players#edit
player GET /players/:id(.:format) players#show
PUT /players/:id(.:format) players#update
DELETE /players/:id(.:format) players#destroy
player_steps GET /player_steps(.:format) player_steps#index
POST /player_steps(.:format) player_steps#create
new_player_step GET /player_steps/new(.:format) player_steps#new
edit_player_step GET /player_steps/:id/edit(.:format) player_steps#edit
player_step GET /player_steps/:id(.:format) player_steps#show
PUT /player_steps/:id(.:format) player_steps#update
DELETE /player_steps/:id(.:format) player_steps#destroy
coach_steps GET /coach_steps(.:format) coach_steps#index
POST /coach_steps(.:format) coach_steps#create
new_coach_step GET /coach_steps/new(.:format) coach_steps#new
edit_coach_step GET /coach_steps/:id/edit(.:format) coach_steps#edit
coach_step GET /coach_steps/:id(.:format) coach_steps#show
PUT /coach_steps/:id(.:format) coach_steps#update
DELETE /coach_steps/:id(.:format) coach_steps#destroy
candidates GET /candidates(.:format) candidates#index
POST /candidates(.:format) candidates#create
new_candidate GET /candidates/new(.:format) candidates#new
edit_candidate GET /candidates/:id/edit(.:format) candidates#edit
candidate GET /candidates/:id(.:format) candidates#show
PUT /candidates/:id(.:format) candidates#update
DELETE /candidates/:id(.:format) candidates#destroy
payment_notifications GET /payment_notifications(.:format) payment_notifications#show
post GET /posts/:id(.:format) posts#show
posts GET /posts(.:format) posts#index
admin_posts_path GET /admin/posts(.:format) admin/posts#index
admin_posts_path POST /admin/posts(.:format) admin/posts#index
admin_post_path GET /admin/posts/:id(.:format) admin/posts#show
new_admin_post_path GET /admin/posts/new(.:format) admin/posts#new
/*a(.:format) errors#routing
choose GET /user_type(.:format) home#user_type
root / devise/sessions#new
Also tried this
<h2><%= link_to post.title, url_for([#post]) %></h2>
this throw:::: Nil location provided. Can't build URI.
=( any documentation on doing this, ?? do you know where i can find it
Routes.rb
Consult::Application.routes.draw do
devise_for :users, :controllers => { :registrations => "registrations" }
scope "/admin" do
resources :users, :controller => 'admin/users'
resources :posts, :controller => 'admin/posts'
end
resources :players
resources :player_steps
resources :coach_steps
resources :candidates
resource :payment_notifications, :only => :show
#match 'candidates' => 'candidates#index'
#resources :posts
get '/posts/:id', to: 'posts#show', as: 'post'
get '/posts/', to: 'posts#index', as: 'posts'
get '/admin/posts/', to: 'admin/posts#index', as: 'admin_posts_path'
post '/admin/posts/', to: 'admin/posts#index', as: 'admin_posts_path'
get '/admin/posts/:id', to: 'admin/posts#show', as: 'admin_post_path'
get '/admin/posts/new', to: 'admin/posts#new', as: 'new_admin_post_path'
match '*a', :to => 'errors#routing'
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end
# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
#root :to => "devise/sessions#new"
get 'user_type', to: 'home#user_type', as: :choose
devise_scope :user do
root :to => "devise/sessions#new"
end
# See how all your routes lay out with "rake routes"
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id))(.:format)'
end
Try using namespace, as opposed to the scope, as the namespace is much better for nesting. your routes file should look something like this.
namespace :admin do
resources :users
resources :posts
end
resources :players
resources :player_steps
resources :coach_steps
resources :candidates
resource :payment_notifications, :only => :show
#match 'candidates' => 'candidates#index'
resources :posts
you can remove
get '/posts/:id', to: 'posts#show', as: 'post'
get '/posts/', to: 'posts#index', as: 'posts'
get '/admin/posts/', to: 'admin/posts#index', as: 'admin_posts_path'
post '/admin/posts/', to: 'admin/posts#index', as: 'admin_posts_path'
get '/admin/posts/:id', to: 'admin/posts#show', as: 'admin_post_path'
get '/admin/posts/new', to: 'admin/posts#new', as: 'new_admin_post_path'
as the namespace and the resources handle their generation
full routes file should be
Consult::Application.routes.draw do
devise_for :users, :controllers => { :registrations => "registrations" }
namespace :admin do
resources :users
resources :posts
end
resources :players
resources :player_steps
resources :coach_steps
resources :candidates
resources :posts
resource :payment_notifications, :only => :show
get 'user_type', to: 'home#user_type', as: :choose
devise_scope :user do
root :to => "devise/sessions#new"
end
end
I am following along with Michael Hartl's Ruby on Rails Tutorial 2nd Edition and have reached the signin/signout section of the book.
So far I can create a new user (or in my case landlord) and log in with the new credentials. The problem I have is when signing out. I click "signout" and get a route error saying:
No route matches [GET] "/signout"
Below are code snippets. Any help would be very appreciated!
rake routes output
landlords GET /landlords(.:format) landlords#index
POST /landlords(.:format) landlords#create
new_landlord GET /landlords/new(.:format) landlords#new
edit_landlord GET /landlords/:id/edit(.:format) landlords#edit
landlord GET /landlords/:id(.:format) landlords#show
PUT /landlords/:id(.:format) landlords#update
DELETE /landlords/:id(.:format) landlords#destroy
properties GET /properties(.:format) properties#index
POST /properties(.:format) properties#create
new_property GET /properties/new(.:format) properties#new
edit_property GET /properties/:id/edit(.:format) properties#edit
property GET /properties/:id(.:format) properties#show
PUT /properties/:id(.:format) properties#update
DELETE /properties/:id(.:format) properties#destroy
sessions POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
session DELETE /sessions/:id(.:format) sessions#destroy
root / content_pages#home
content_pages_home GET /content_pages/home(.:format) content_pages#home
help /help(.:format) content_pages#help
questions /questions(.:format) content_pages#questions
signup /signup(.:format) landlords#new
signin /signin(.:format) sessions#new
signout DELETE /signout(.:format) sessions#destroy
routes.rb file
resources :landlords
resources :properties
resources :sessions, only: [:new, :create, :destroy]
root :to => 'content_pages#home'
get "content_pages/home"
match '/help', to: 'content_pages#help'
match '/questions', to: 'content_pages#questions'
match '/signup', to: 'landlords#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete
link to signout
<%= link_to "Signout", signout_path, method: "delete" %>
sessions controller
def destroy
sign_out
redirect_to root_path
end
The via: option in the following code restricts the request to the delete method:
match '/signout', to: 'sessions#destroy', via: :delete
You'll need to make one that works with the 'get' method
Check out the Rails Routing guide