Rails Cookie Detection Script Fails - ruby-on-rails

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

Related

Undefined method or local variable in rails

undefined local variable or method `requestuser_path' for #<#<Class:0x007f92de073e10>:0x007f92e191a020>
I don't know why this error occurs even though I route to the required controller and the view is also no problem here.
# routes.rb
resources :users do
member do
get :following, :followers
end
end
resources :sessions, only: [:new, :create, :destroy]
resources :microposts, only: [:create, :destroy]
resources :relationships, only: [:create, :destroy]
#resources :requests, only: [:create]
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 '/request', to: 'users#requestuser'
The named route:
<% if signed_in? %>
<li><%= link_to "Requests", requestuser_path %></li>
<% end %>
UsersController:
def requestuser
#title = "Requests"
#user = User.find(params[:id])
#users = #user.followed_users.paginate(page: params[:page])
end
I think there is an error in the named route as I am new to Rails. I don't know what is the cause of error. The named route is predefined or how does it work.
I need to learn more topics on Rails can someone tell which is the best site to learn after beginner stage.
The requestuser_path route helper method does not exist.
Unless specified, route helper methods are autogenerated in Rails. To see a list of all these helpers and their corresponding controllers and actions, go to http://localhost:3000/rails/info/routes assuming you are running your development Rails server on port 3000.
In your case, the method you are looking for is request_path, not requestuser_path
To learn more about routes in Rails, the official documentation is a good resource. https://guides.rubyonrails.org/routing.html
Try not to use ruby keyword as routes or any controller's or model's name. Ruby will throw error. Try to rename the routes "match '/request', to: 'users#requestuser'"
It's always a good practice to run rails routes or rake routes to see how rails generates your routes, in your case pleas use request_path
It's not recommended to use match and even considered invalid in newer rails version:
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"

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.

I get error "uninitialized constant ContactController"

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'

Google authentification error "no route match"

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!

Rails app w/ Heroku - Home page doesn't exist

My app runs perfectly on my localhost, but when I push it to Heroku, my home page gives me a message that says 'The page you were looking for doesn't exist.' Other pages (not all, but most) within the app display correctly on Heroku. Here is the output from running heroku run cat config/routes.rb:
Running `cat config/routes.rb` attached to terminal... up, run.8019
SampleApp::Application.routes.draw do
resources :users
resources :sessions, only: [:new, :create, :destroy]
resources :relationships, only: [:create, :destroy]
resources :teams
resources :players
resources :matchups
root 'static_pages#home'
match '/signup', to: 'users#new', via: 'get'
match '/signin', to: 'sessions#new', via: 'get'
match '/signout', to: 'sessions#destroy', via: 'delete'
match '/help', to: 'static_pages#help', via: 'get'
match '/about', to: 'static_pages#about', via: 'get'
match '/contact', to: 'static_pages#contact', via: 'get'
match '/updatepts', to: 'static_pages#updatepts', via: 'get'
match '/findMatchup', to: 'static_pages#findMatchup', via: 'get'
The other page that notably does not display is matchups/:id. Any ideas as to why this is displaying with no problem locally, but will not work on Heroku? Thanks!
Edit: I am running Rails 4 w/ Ruby 2.
My underlying problem was that a partial that was being rendered on my home page (and the one other page not displaying) was calling a field that was nil because the data in my heroku database was not as extensive as the data in my local database.

Resources