routes.rb file is
Rails.application.routes.draw do
root 'pages#home'
match '/contact', to: 'pages#contact', via: 'get'
match '/home', to: 'contact#pages', via: 'get'
pages_controller is
class PagesController < ApplicationController
def home
end
def contact
end
end
I get routing error saying "uninitialized constant ContactController". Does anyone know how to fix this?
Do Change your routes.rb file
Rails.application.routes.draw do
root 'pages#home'
match '/contact', to: 'pages#contact', via: :get
match '/home', to: 'pages#home', via: :get
end
Would work!!!
In Rails 4 with match methods must specify HTTP method otherwise would get RuntimeError "You should not use the match method in your router without specifying an HTTP method. (RuntimeError)"
match is deprecated. Try
root 'pages#home'
get '/contact', to: 'pages#contact'
get '/home', to: 'pages#home'
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.
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!
I have write down this in routes file
resources :users
match '/signup', to: 'users#new', via: [:POST, :get, :post]
match '/edit_user', to: 'users#edit', via: 'get'
and this is my function in users controller
def edit
#user = User.find(params[:id])
end
I am getting error Please help me..
No route matches [GET] "/edit_user/1"
match '/edit_user', to: 'users#edit', via: 'get'
You are missing the /:id on the route. Fixed:
match '/edit_user/:id', to: 'users#edit', via: 'get'
I wanted to make sure that users have cookies enabled for my site, so I used this guide.
However, when I run my server, I gut this error:
syntax error, unexpected $end, expecting keyword_end
map.cookies_test “cookie_test”, :controller...
Here's my application_controller.rb :
class ApplicationController < ActionController::Base
protect_from_forgery
include CookieDetection
include SessionsHelper
end
and my routes.rb :
Basketball::Application.routes.draw do
map.cookies_test “cookie_test”, :controller => “application”, :action => “cookie_test”
resources :games
resources :teams
get "teams/new"
get "games/new"
resources :users
resources :sessions, only: [:new, :create, :destroy]
root to: 'static_pages#home'
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
end
Update
I have changed my quotes from "smart" quotes to plain quotes (as per Edward), but I am now getting the error:
undefined local variable or method `map' for#
<ActionDispatch::Routing::Mapper:0x007ff9ca996800> (NameError)
Update
I have changed Map to Match (as per Edward) and am now getting the error:
`match': wrong number of arguments (0 for 1) (ArgumentError)
In your routes file, it look like you've got "smart" quotes “” ,rather than plain "
I expect you've cut and pasted them by mistake.
Edit
Change map to match - map is rails 2
Setting up my second project in Rails (first not following a tutorial) and have run into a problem I can't solve with my routes. Everything works as I'd like it to with my routes.rb file like:
AnimalApp::Application.routes.draw do
root to: 'static_pages#index'
# resources :animal
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
match '/league', to: 'static_pages#league'
match '/animal', to: 'animal#new'
Except I can't access my animals! Going to /animal/1 throws an error :
No route matches [GET] "/animal/1"
To fix this I changed my routes as follows:
AnimalApp::Application.routes.draw do
root to: 'static_pages#index'
resources :animal
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
match '/league', to: 'static_pages#league'
#match '/animal', to: 'animal#new'
However, when I try and view any of the other pages on my site I get the following error:
No route matches {:action=>"show", :controller=>"animal"}
For more information see below my controllers:
(static pages)
class StaticPagesController < ApplicationController
def help
end
def league
end
def contact
end
def about
end
def index
end
def show
end
end
animals controller
class AnimalController < ApplicationController
def new
#animal = Animal.new
end
def show
#animal = Animal.new
end
end
And, also, I've run rake routes I get:
animal_index GET /animal(.:format) animal#index
POST /animal(.:format) animal#create
new_animal GET /animal/new(.:format) animal#new
edit_animal GET /animal/:id/edit(.:format) animal#edit
animal GET /animal/:id(.:format) animal#show
PUT /animal/:id(.:format) animal#update
DELETE /animal/:id(.:format) animal#destroy
root / static_pages#index
help /help(.:format) static_pages#help
about /about(.:format) static_pages#about
contact /contact(.:format) static_pages#contact
league /league(.:format) static_pages#league
/animal(.:format) animal#new
Does anybody have any idea how I can get my site back and also allow myself to see objects in my animal database under the URI /animal/[:id]?
Make it resources :animals instead of resources :animal
rake routes should show the following output:
animals GET /animals(.:format) animals#index
POST /animals(.:format) animals#create
new_animal GET /animals/new(.:format) animals#new
edit_animal GET /animals/:id/edit(.:format) animals#edit
animal GET /animals/:id(.:format) animals#show
PUT /animals/:id(.:format) animals#update
DELETE /animals/:id(.:format) animals#destroy