Google authentification error "no route match" - ruby-on-rails

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!

Related

rails ArgumentError: You should not use the `match` method in your router without specifying an HTTP method

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.

Rails - missing routes helper prefix

I am missing the contacts#show prefix 'contact' as seen below.
rake routes
contacts GET /contacts(.:format) contacts#index
POST /contacts(.:format) contacts#create
new_contact GET /contacts/new(.:format) contacts#new
edit_contact GET /contacts/:id/edit(.:format) contacts#edit
GET /contacts/:id(.:format) contacts#show
PATCH /contacts/:id(.:format) contacts#update
PUT /contacts/:id(.:format) contacts#update
DELETE /contacts/:id(.:format) contacts#destroy
I am thinking this is the reason why I am getting a dot instead of a slash when clicking the following link.
_contact.html.erb
<%= link_to "delete contact", contact, method: :delete,
data: { confirm: "You sure?" } %>
The server logs the proper DELETE request, however, cannot render /contact.26 instead of the correct /contacts/26.
Started DELETE "/contact.26" for 128.177.12.30 at 2016-04-13 21:04:30 +0000
ActionController::RoutingError (No route matches [DELETE] "/contact.26"):
Every post I've come across with a dot instead of a slash seems to stem from a pluralization error, however, I don't believe this is the case here.
In addition, I've removed resources :contacts from my routes file, run $ rake routes, added resources :contacts, run $ rake routes, and the problem persists.
This problem seems to be unique to the contacts model, as the rest of my models aren't missing any prefixes or having this error when deleting.
How do I add the 'contact' prefix back to 'contacts#show'?
routes.rb file for reference:
Rails.application.routes.draw do
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'
get 'newevent' => 'events#new'
get 'newteam' => 'teams#new'
get 'newperformance' => 'performances#new'
get 'newhotel' => 'hotels#new'
get 'newcontact' => 'contacts#new'
get 'newflight' => 'flights#new'
get 'newground' => 'grounds#new'
get 'newguest' => 'guests#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
resources :users
resources :events
resources :teams do
member do
get :events
end
end
resources :performances
resources :hotels
resources :contacts
resources :flights
resources :grounds
resources :guests
resources :account_activations, only: [:edit]
resources :password_resets, only: [:new, :create, :edit, :update]
end
you may have a conflict between the routes set by
resources :contacts
and
get 'contact' => 'static_pages#contact'
The easiest solution is probably to change the static page's links. Best to keep the resources together if you can.
I just came across this same error.
the fix to my issue was that 's' at the end of resources
I had 'resource', and getting the same problem as you.
I changed it to 'resources' and it fixed my problem
in my case was just a typo.
This error showed up for me yesterday. What fixed it was deleting helper files that were not being used. Might be worth a try for you.

Template is missing ruby-on-rails

localhost says that template is missing. routes.rb:
Rails.application.routes.draw do
root 'home#index'
resources :sessions, only: [:new, :create, :destroy]
get 'signup' => 'users#new'
get 'signin' => 'sessions#new'
delete 'signout' => 'sessions#destroy'
get 'about' => 'static_pages#about'
match '*path' => 'application#routing_error', via: :all
end
nothing in my home_controller.rb
any idea to fix this?
You probably already have a home folder under view. If not, create the folder. Then add a index.html.erb with a heading like this:
<h1>Welcome!</h1>
hope this helps
edit
You should define and index method too! (not necessary)
In addition to #YahsHef's answer.. You state that
Nothing in my home_controller.rb
You'll also need the index method to exist.
class HomeController < ApplicationController
def index
end
end
in order to render the view.

Routing Error Active Admin and Devise

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:)

Refactoring Rails Routes to still pass testing

I can't get this to pass:
%w[home help about contact].each do |page|
get :controller => 'static_pages', :action => page
end
I was trying to refactor this code:
get 'static_pages/home'
get 'static_pages/help'
get 'static_pages/about'
get 'static_pages/contact'
Please help.
static_pages = %w(home help about contact).map {|p| p.to_sym}
resources :static_pages, only: static_pages do
static_pages.each do |page|
get page, on: :collection
end
end
render
$ rake routes
home_static_pages GET /static_pages/home(.:format) static_pages#home
help_static_pages GET /static_pages/help(.:format) static_pages#help
about_static_pages GET /static_pages/about(.:format) static_pages#about
contact_static_pages GET /static_pages/contact(.:format) static_pages#contact
use only: static_pages to not generate CRUD routes.
I guess if you don't like the original code of:
root to: 'static_pages#home'
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
and you want to get the same routes, you could go with a simple loop like:
root to: 'static_pages#home'
%w(help about contact).each do |page|
get "#{page}" => "static_pages##{page}"
end
Though, to me this doesn't really seem like enough of a refactor to justify it.
Edit
To fix the errors on your code, use:
%w(home help about contact).each do |page|
get "/#{page}", :controller => 'static_pages', :action => page
end
Check the api for match for valid arguments to get.

Resources